Skip to content

Commit 3eca75f

Browse files
committed
chore(ci): qualify compiler cache ownership and retention guards
1 parent e7ff38c commit 3eca75f

2 files changed

Lines changed: 185 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: ci-cache-policy-proof
2+
on:
3+
push:
4+
branches: [codex/ci-cache-policy-proof]
5+
permissions:
6+
contents: read
7+
jobs:
8+
cli:
9+
runs-on: ubuntu-24.04
10+
timeout-minutes: 15
11+
steps:
12+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
13+
- uses: ./.github/actions/setup
14+
with:
15+
provider: github
16+
- name: Exercise actual filesystem CLI boundaries
17+
run: bun run test:scripts scripts/prune-turbopack-cache.test.ts --reporter=default --reporter=json --outputFile.json="$RUNNER_TEMP/cache-policy-tests.json"
18+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
19+
if: always()
20+
with:
21+
name: cache-policy-tests
22+
path: ${{ runner.temp }}/cache-policy-tests.json
23+
lifecycle-write:
24+
runs-on: blacksmith-2vcpu-ubuntu-2404
25+
steps:
26+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
27+
- uses: ./.github/actions/cache
28+
with:
29+
provider: blacksmith
30+
key: ${{ github.repository }}-compiler-requalification-44040218009
31+
path: ./apps/sim/.next/cache
32+
- name: Verify prior deletion and seed lifecycle marker
33+
run: |
34+
python3 - <<'PYCODE'
35+
from pathlib import Path
36+
import json,os
37+
p=Path('apps/sim/.next/cache');entries=list(p.iterdir());report={'restoredEntries':len(entries)}
38+
Path(os.environ['RUNNER_TEMP'],'lifecycle-write.json').write_text(json.dumps(report))
39+
assert not entries,'Completed compiler cleanup was not restored'
40+
(p/'lifecycle-marker').write_text('owned-cache-lifecycle-proof')
41+
PYCODE
42+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
43+
if: always()
44+
with:
45+
name: lifecycle-write
46+
path: ${{ runner.temp }}/lifecycle-write.json
47+
lifecycle-delete:
48+
needs: lifecycle-write
49+
runs-on: blacksmith-2vcpu-ubuntu-2404
50+
steps:
51+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
52+
- uses: ./.github/actions/cache
53+
with:
54+
provider: blacksmith
55+
key: ${{ github.repository }}-compiler-requalification-44040218009
56+
path: ./apps/sim/.next/cache
57+
- name: Verify marker persisted then delete it
58+
run: |
59+
python3 - <<'PYCODE'
60+
from pathlib import Path
61+
import json,os
62+
p=Path('apps/sim/.next/cache/lifecycle-marker');found=p.exists()
63+
Path(os.environ['RUNNER_TEMP'],'lifecycle-delete.json').write_text(json.dumps({'markerRestored':found}))
64+
assert found and p.read_text()=='owned-cache-lifecycle-proof'
65+
p.unlink()
66+
PYCODE
67+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
68+
if: always()
69+
with:
70+
name: lifecycle-delete
71+
path: ${{ runner.temp }}/lifecycle-delete.json
72+
lifecycle-verify:
73+
needs: lifecycle-delete
74+
runs-on: blacksmith-2vcpu-ubuntu-2404
75+
steps:
76+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
77+
- uses: ./.github/actions/cache
78+
with:
79+
provider: blacksmith
80+
key: ${{ github.repository }}-compiler-requalification-44040218009
81+
path: ./apps/sim/.next/cache
82+
- name: Verify deletion survived another runner
83+
run: |
84+
python3 - <<'PYCODE'
85+
from pathlib import Path
86+
import json,os
87+
entries=list(Path('apps/sim/.next/cache').iterdir())
88+
Path(os.environ['RUNNER_TEMP'],'lifecycle-verify.json').write_text(json.dumps({'remainingEntries':len(entries)}))
89+
assert not entries,'Deleted cache marker returned on a fresh runner'
90+
PYCODE
91+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
92+
if: always()
93+
with:
94+
name: lifecycle-verify
95+
path: ${{ runner.temp }}/lifecycle-verify.json
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { spawnSync } from 'node:child_process'
2+
import {
3+
existsSync,
4+
mkdirSync,
5+
mkdtempSync,
6+
readdirSync,
7+
rmSync,
8+
statSync,
9+
symlinkSync,
10+
writeFileSync,
11+
} from 'node:fs'
12+
import { tmpdir } from 'node:os'
13+
import { join, resolve } from 'node:path'
14+
import { afterEach, describe, expect, it } from 'vitest'
15+
16+
const script = resolve(import.meta.dirname, 'prune-turbopack-cache.ts')
17+
const fixtures: string[] = []
18+
19+
function fixture() {
20+
const root = mkdtempSync(join(tmpdir(), 'sim-compiler-cache-'))
21+
fixtures.push(root)
22+
const build = join(root, '.next/cache')
23+
const dev = join(root, '.next/dev/cache/turbopack')
24+
const outside = join(root, 'unrelated')
25+
for (const dir of [build, dev, outside]) {
26+
mkdirSync(dir, { recursive: true })
27+
writeFileSync(join(dir, 'state'), Buffer.alloc(4_096))
28+
}
29+
symlinkSync(outside, join(build, 'linked'), process.platform === 'win32' ? 'junction' : 'dir')
30+
return { root, build, dev, outside }
31+
}
32+
33+
function run(root: string, args: string[], maximum = '0.000001') {
34+
return spawnSync('bun', [script, ...args], {
35+
cwd: root,
36+
encoding: 'utf8',
37+
timeout: 10_000,
38+
env: { ...process.env, SIM_TURBOPACK_CACHE_MAX_GB: maximum },
39+
})
40+
}
41+
42+
afterEach(() => {
43+
for (const root of fixtures.splice(0)) rmSync(root, { recursive: true, force: true })
44+
})
45+
46+
describe('compiler cache maintenance through the real CLI', () => {
47+
it.each(['size', 'force'])('clears only build contents by %s while preserving its mount', (mode) => {
48+
const { root, build, dev, outside } = fixture()
49+
const inode = statSync(build).ino
50+
const result = run(root, mode === 'force' ? ['--build', '--force'] : ['--build'], mode === 'force' ? '1' : undefined)
51+
expect(result.status, result.stderr).toBe(0)
52+
expect(existsSync(build)).toBe(true)
53+
expect(statSync(build).ino).toBe(inode)
54+
expect(readdirSync(build)).toEqual([])
55+
expect(existsSync(join(dev, 'state'))).toBe(true)
56+
expect(existsSync(join(outside, 'state'))).toBe(true)
57+
})
58+
59+
it('does not substitute dev state when the build cache is absent', () => {
60+
const { root, build, dev } = fixture()
61+
rmSync(build, { recursive: true })
62+
expect(run(root, ['--build']).status).toBe(0)
63+
expect(existsSync(join(dev, 'state'))).toBe(true)
64+
})
65+
66+
it('keeps the existing dev command scoped to dev state', () => {
67+
const { root, build, dev, outside } = fixture()
68+
expect(run(root, []).status).toBe(0)
69+
expect(existsSync(dev)).toBe(false)
70+
expect(existsSync(join(build, 'state'))).toBe(true)
71+
expect(existsSync(join(outside, 'state'))).toBe(true)
72+
})
73+
74+
it('leaves both caches intact for a build dry run', () => {
75+
const { root, build, dev } = fixture()
76+
expect(run(root, ['--build', '--dry-run']).status).toBe(0)
77+
expect(existsSync(join(build, 'state'))).toBe(true)
78+
expect(existsSync(join(dev, 'state'))).toBe(true)
79+
})
80+
81+
it('refuses a symlink build root without deleting its target', () => {
82+
const { root, build, dev, outside } = fixture()
83+
rmSync(build, { recursive: true })
84+
symlinkSync(outside, build, process.platform === 'win32' ? 'junction' : 'dir')
85+
const result = run(root, ['--build', '--force'])
86+
expect(result.status, result.stderr).not.toBe(0)
87+
expect(existsSync(join(outside, 'state'))).toBe(true)
88+
expect(existsSync(join(dev, 'state'))).toBe(true)
89+
})
90+
})

0 commit comments

Comments
 (0)