ReviewOS

also looking at this

pantry-pm/pantry

fix: preserve sources when removing linked workspace directories

#247
Merged chris wants to merge codex/preserve-linked-workspace-sources into main
4 files +98 -46
.github/scripts/windows-native-runtime.tsmodified+27-1
Changes to .github/scripts/windows-native-runtime.ts
@@ -1,5 +1,5 @@
11import assert from 'node:assert/strict'
2import { cp, mkdir, mkdtemp, readFile, realpath, rm } from 'node:fs/promises'
2import { cp, mkdir, mkdtemp, readFile, realpath, rm, symlink } from 'node:fs/promises'
33import { tmpdir } from 'node:os'
44import { join, resolve } from 'node:path'
55
@@ -48,6 +48,32 @@ try {
4848 proof.sdkRuntimeSha256 = originalHash
4949 proof.nativeRuntimeReusedAndActivated = true
5050
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
5177 // Exercise the bundled Action itself. A missing local dependency must fail
5278 // inside workspace installation, before the Action can say setup completed.
5379 const negative = join(owned, 'required-workspace-failure')