|
| 1 | +// CHANGE: pin the standalone base-image clone target to the dev-owned app folder |
| 2 | +// WHY: entrypoint runs `git clone` as `su - dev`; cloning into a root-owned dir (e.g. /work/app) |
| 3 | +// fails with permission denied, so the repo never lands in the prepared `app` folder |
| 4 | +// QUOTE(ТЗ): "Почему-то при docker-git clone не делается git clone в папку app" |
| 5 | +// REF: issue-408 |
| 6 | +// SOURCE: n/a |
| 7 | +// FORMAT THEOREM: defaultTargetDir(entrypoint) = appDir(Dockerfile) ∧ appDir ⊂ chown(dev, /home/dev) |
| 8 | +// PURITY: SHELL (reads repository source files) |
| 9 | +// INVARIANT: clone target is owned by the unprivileged clone user |
| 10 | +// COMPLEXITY: O(|file|) |
| 11 | +import { describe, expect, it } from "@effect/vitest" |
| 12 | +import { readFileSync } from "node:fs" |
| 13 | +import path from "node:path" |
| 14 | +import { fileURLToPath } from "node:url" |
| 15 | + |
| 16 | +const __filename = fileURLToPath(import.meta.url) |
| 17 | +const __dirname = path.dirname(__filename) |
| 18 | +// packages/lib/tests/shell -> repository root |
| 19 | +const repoRoot = path.resolve(__dirname, "..", "..", "..", "..") |
| 20 | + |
| 21 | +const readRepoFile = (relativePath: string): string => |
| 22 | + readFileSync(path.join(repoRoot, relativePath), "utf8") |
| 23 | + |
| 24 | +describe("standalone base-image clone target", () => { |
| 25 | + const entrypoint = readRepoFile("entrypoint.sh") |
| 26 | + const dockerfile = readRepoFile("Dockerfile") |
| 27 | + |
| 28 | + // CHANGE: derive the dev home that the Dockerfile recursively chowns to the clone user |
| 29 | + // WHY: `git clone` runs as `su - dev`, so the target must live under a dev-owned path |
| 30 | + // PURITY: CORE |
| 31 | + // INVARIANT: chownedHome captures the `chown -R dev:dev <home>` argument |
| 32 | + const chownedHome = (() => { |
| 33 | + const match = dockerfile.match(/chown -R dev:dev (\/home\/dev)\b/) |
| 34 | + return match?.[1] |
| 35 | + })() |
| 36 | + |
| 37 | + // CHANGE: derive the default TARGET_DIR the entrypoint clones into |
| 38 | + // WHY: the bug is a wrong default that points outside the dev-owned home |
| 39 | + // PURITY: CORE |
| 40 | + // INVARIANT: defaultTargetDir captures `TARGET_DIR="${TARGET_DIR:-<default>}"` |
| 41 | + const defaultTargetDir = (() => { |
| 42 | + const match = entrypoint.match(/TARGET_DIR="\$\{TARGET_DIR:-([^}]+)\}"/) |
| 43 | + return match?.[1] |
| 44 | + })() |
| 45 | + |
| 46 | + it("prepares an app folder under the dev home in the Dockerfile", () => { |
| 47 | + expect(dockerfile).toContain("mkdir -p /home/dev/app") |
| 48 | + expect(chownedHome).toBe("/home/dev") |
| 49 | + }) |
| 50 | + |
| 51 | + it("defaults the clone target to the prepared app folder", () => { |
| 52 | + expect(defaultTargetDir).toBe("/home/dev/app") |
| 53 | + }) |
| 54 | + |
| 55 | + it("keeps the clone target under the dev-owned home so `su - dev` can write into it", () => { |
| 56 | + expect(defaultTargetDir).toBeDefined() |
| 57 | + expect(chownedHome).toBeDefined() |
| 58 | + expect(`${defaultTargetDir}/`.startsWith(`${chownedHome}/`)).toBe(true) |
| 59 | + }) |
| 60 | +}) |
0 commit comments