also looking at this
fix: preserve sources when removing linked workspace directories
#247
4 files
+98
-46
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import assert from 'node:assert/strict' |
| 2 | import { cp, mkdir, mkdtemp, readFile, realpath, rm } from 'node:fs/promises' | |
| 2 | import { cp, mkdir, mkdtemp, readFile, realpath, rm, symlink } from 'node:fs/promises' | |
| 3 | 3 | import { tmpdir } from 'node:os' |
| 4 | 4 | import { join, resolve } from 'node:path' |
| 5 | 5 | |
| @@ -48,6 +48,32 @@ try { | ||
| 48 | 48 | proof.sdkRuntimeSha256 = originalHash |
| 49 | 49 | proof.nativeRuntimeReusedAndActivated = true |
| 50 | 50 | |
| 51 | // Cached workspace links point back into the source checkout. Reconciliation | |
| 52 | // must replace the directory link itself, never walk and empty its target. | |
| 53 | const workspace = join(owned, 'linked-workspaces') | |
| 54 | const member = join(workspace, 'packages/zig') | |
| 55 | await mkdir(member, { recursive: true }) | |
| 56 | await mkdir(join(workspace, 'pantry')) | |
| 57 | await Bun.write(join(workspace, 'pantry.jsonc'), JSON.stringify({ dependencies: {} })) | |
| 58 | await Bun.write(join(workspace, 'package.json'), JSON.stringify({ name: 'linked-workspace-fixture', private: true, workspaces: ['packages/*'] })) | |
| 59 | await Bun.write(join(member, 'pantry.json'), JSON.stringify({ name: 'zig', version: '1.0.0' })) | |
| 60 | const source = join(member, 'build.zig') | |
| 61 | await Bun.write(source, 'tracked workspace source\n') | |
| 62 | const sourceHash = Bun.SHA256.hash(await readFile(source), 'hex') | |
| 63 | for (const type of ['dir', 'junction'] as const) { | |
| 64 | const link = join(workspace, 'pantry/zig') | |
| 65 | await rm(link, { recursive: true, force: true }) | |
| 66 | await symlink(member, link, type) | |
| 67 | for (const attempt of [1, 2]) { | |
| 68 | const result = await run(`workspace-relink-${type}-${attempt}`, [cli, 'install', '--no-save', '--verbose'], workspace) | |
| 69 | assert.match(result, /Linked 1 workspace package/) | |
| 70 | assert.equal(Bun.SHA256.hash(await readFile(source), 'hex'), sourceHash) | |
| 71 | assert.equal(await realpath(link), await realpath(member)) | |
| 72 | } | |
| 73 | } | |
| 74 | proof.workspaceSourcePreservedThroughRepeatedRelinking = true | |
| 75 | proof.workspaceSourceSha256 = sourceHash | |
| 76 | ||
| 51 | 77 | // Exercise the bundled Action itself. A missing local dependency must fail |
| 52 | 78 | // inside workspace installation, before the Action can say setup completed. |
| 53 | 79 | const negative = join(owned, 'required-workspace-failure') |