-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ship): a committed cache can no longer shadow the live one (sc-1489) #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
norvalbv
wants to merge
2
commits into
main
Choose a base branch
from
fix/sc-1489-receipt-shadow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { afterAll, describe, expect, it } from 'vitest'; | ||
| import { testExecFileSync as execFileSync, testSpawnSync as spawnSync } from './_helpers.mts'; | ||
|
|
||
| // sc-1489: a consumer committed `.qavis/receipt.json`, so the base checkout kept putting a stale copy | ||
| // in the ship worktree, the link was skipped as "already present", and the qavis-advisory gate could | ||
| // never be cleared by running qavis — GUARD_QAVIS_OK=1 was the only exit. | ||
|
|
||
| const scriptPath = fileURLToPath(new URL('../lib/ship/ship-branch.sh', import.meta.url)); | ||
| const GENV = { GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_SYSTEM: '/dev/null' }; | ||
| const WT_RE = /worktree kept at (.+?)\. Remove/; | ||
| const dirs: string[] = []; | ||
| afterAll(() => { | ||
| for (const d of dirs) rmSync(d, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| // The hook reports the receipt's CONTENT. Presence is not enough to see this bug: the shadow handed | ||
| // the gate a file, just the wrong one, so a `-e` probe passes straight through it. | ||
| const HOOK = | ||
| '#!/bin/sh\ngrep -q live .qavis/receipt.json 2>/dev/null && echo RECEIPT_LIVE || echo RECEIPT_STALE\nexit 0\n'; | ||
|
|
||
| function seedRepo() { | ||
| const dir = mkdtempSync(join(tmpdir(), 'shipcache-')); | ||
| dirs.push(dir); | ||
| const env = { ...process.env, ...GENV }; | ||
| const git = (args: string[], opts = {}) => | ||
| execFileSync('git', args, { cwd: dir, env, encoding: 'utf8', ...opts }); | ||
| mkdirSync(join(dir, '.husky/_'), { recursive: true }); | ||
| writeFileSync(join(dir, '.husky/.keep'), ''); | ||
| writeFileSync(join(dir, '.husky/_/pre-commit'), HOOK); // gitignored runner; ship fails closed without it | ||
| chmodSync(join(dir, '.husky/_/pre-commit'), 0o755); | ||
| for (const a of [ | ||
| ['init', '-q', '-b', 'work'], | ||
| ['config', 'user.email', 'a@b.c'], | ||
| ['config', 'user.name', 'a'], | ||
| ['config', 'commit.gpgsign', 'false'], | ||
| ['add', '.husky/.keep'], | ||
| ['commit', '-q', '-m', 'base'], | ||
| ['config', 'core.hooksPath', '.husky/_'], | ||
| ['remote', 'add', 'origin', 'git@github.com:acme/app.git'], | ||
| ]) | ||
| git(a, { stdio: 'ignore' }); | ||
| mkdirSync(join(dir, '.qavis'), { recursive: true }); | ||
| writeFileSync(join(dir, '.qavis/recipe.json'), '{"from":"acme/qavis"}\n'); | ||
| return { dir, env, git }; | ||
| } | ||
|
|
||
| function ship(dir: string, env: NodeJS.ProcessEnv, git, branch: string, paths = ['note.txt']) { | ||
| const r = spawnSync('/bin/bash', [scriptPath, branch, 't', ...paths], { | ||
| cwd: dir, | ||
| input: 'b\n', | ||
| encoding: 'utf8', | ||
| env: { ...env, SHIP_DRY_RUN: '1' }, | ||
| }); | ||
| const wt = WT_RE.exec(r.stderr)?.[1]; // dry-run keeps it; drop so afterAll's rm isn't blocked | ||
| if (wt) { | ||
| try { | ||
| git(['worktree', 'remove', '--force', wt], { stdio: 'ignore' }); | ||
| } catch { | ||
| /* best-effort */ | ||
| } | ||
| } | ||
| return { | ||
| ...r, | ||
| gateLog: () => | ||
| readFileSync(join(dir, `.devkit/last-ship-gates-${branch.replace(/\//g, '-')}.log`), 'utf8'), | ||
| }; | ||
| } | ||
|
|
||
| describe('ship — a committed gate cache must lose to the live one', () => { | ||
| it('links the live receipt over the stale committed copy, without touching the shipped commit', () => { | ||
| const { dir, env, git } = seedRepo(); | ||
| writeFileSync(join(dir, '.qavis/receipt.json'), '{"sha":"stale"}\n'); | ||
| git(['add', '.qavis'], { stdio: 'ignore' }); | ||
| git(['commit', '-q', '-m', 'accidentally track the receipt'], { stdio: 'ignore' }); | ||
| writeFileSync(join(dir, '.qavis/receipt.json'), '{"sha":"live"}\n'); // a real pass, post-commit | ||
| writeFileSync(join(dir, 'note.txt'), 'hi\n'); | ||
|
|
||
| const r = ship(dir, env, git, 'feat/committed-receipt'); | ||
|
|
||
| expect(r.status, r.stderr).toBe(0); | ||
| expect(r.gateLog()).toMatch(/RECEIPT_LIVE/); // the gate read the pass, not the committed staleness | ||
| expect(r.gateLog()).not.toMatch(/RECEIPT_STALE/); | ||
| expect(r.stderr).toMatch(/gate cache\(s\) are COMMITTED/); | ||
| expect(r.stderr).toContain('git rm .qavis/receipt.json'); // pasteable, and landable by ship | ||
| expect(r.stderr).not.toContain('git rm --cached'); // --cached leaves it on disk → ship re-adds it | ||
| // It must not ALSO reach the linked-config classifier, which would tell the operator to commit the | ||
| // very file the notice above says to untrack (and "untracked" is false — the base tracks it). | ||
| expect(r.stderr).not.toMatch(/\.qavis\/receipt\.json \(untracked/); | ||
| expect(r.stderr).not.toMatch(/commit it so gates/); | ||
| // The override is worktree-only: the shipped commit must not delete or rewrite the tracked receipt. | ||
| expect(git(['diff', '--name-only', 'work', 'feat/committed-receipt']).trim()).toBe('note.txt'); | ||
| }); | ||
|
|
||
| // The notice is only worth printing if devkit can LAND what it prints, in the sequence an operator | ||
| // actually follows: `git rm` deletes their live receipt too, so they re-run the tool and it comes | ||
| // back — untracked AND gitignored, exactly what ship's force-add pass sweeps up. Regenerating it here | ||
| // is the whole point of the test; without that write the deletion lands trivially and pins nothing. | ||
| it('lands the untracking even after the tool regenerates the cache', () => { | ||
| const { dir, env, git } = seedRepo(); | ||
| writeFileSync(join(dir, '.qavis/receipt.json'), '{"sha":"stale"}\n'); | ||
| git(['add', '.qavis'], { stdio: 'ignore' }); | ||
| git(['commit', '-q', '-m', 'accidentally track the receipt'], { stdio: 'ignore' }); | ||
| git(['rm', '-q', '.qavis/receipt.json'], { stdio: 'ignore' }); // exactly what the notice prints | ||
| writeFileSync(join(dir, '.gitignore'), '.qavis/receipt.json\n'); | ||
| writeFileSync(join(dir, '.qavis/receipt.json'), '{"sha":"live"}\n'); // `qavis qa` re-run | ||
| writeFileSync(join(dir, 'note.txt'), 'hi\n'); | ||
|
|
||
| const r = ship(dir, env, git, 'feat/untrack-receipt', [ | ||
| '.gitignore', | ||
| '.qavis/receipt.json', | ||
| 'note.txt', | ||
| ]); | ||
|
|
||
| expect(r.status, r.stderr).toBe(0); | ||
| const tree = git(['ls-tree', '-r', '--name-only', 'feat/untrack-receipt']).trim().split('\n'); | ||
| expect(tree).not.toContain('.qavis/receipt.json'); // the defect is gone from the base, for good | ||
| expect(tree).toContain('.gitignore'); | ||
| // Nothing stale reached the worktree, so the notice must stay quiet on the ship that fixes it. | ||
| expect(r.stderr).not.toMatch(/gate cache\(s\) are COMMITTED/); | ||
| // ...and the regenerated cache still reached the gate, so this ship is QA-clearable like any other. | ||
| expect(r.gateLog()).toMatch(/RECEIPT_LIVE/); | ||
| }); | ||
|
|
||
| it('leaves an already-gitignored receipt on the normal link path', () => { | ||
| const { dir, env, git } = seedRepo(); | ||
| writeFileSync(join(dir, '.gitignore'), '.qavis/receipt.json\n'); | ||
| git(['add', '.qavis/recipe.json', '.gitignore'], { stdio: 'ignore' }); | ||
| git(['commit', '-q', '-m', 'track recipe, ignore receipt'], { stdio: 'ignore' }); | ||
| writeFileSync(join(dir, '.qavis/receipt.json'), '{"sha":"live"}\n'); | ||
| writeFileSync(join(dir, 'note.txt'), 'hi\n'); | ||
|
|
||
| const r = ship(dir, env, git, 'feat/ignored-receipt'); | ||
|
|
||
| expect(r.status, r.stderr).toBe(0); | ||
| expect(r.gateLog()).toMatch(/RECEIPT_LIVE/); | ||
| expect(r.stderr).toMatch(/\.qavis\/receipt\.json \(gitignored cache/); | ||
| expect(r.stderr).not.toMatch(/gate cache\(s\) are COMMITTED/); // no false positive | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Clear review-mode environment variables.
seedRepo()copies the parent environment. If the parent sets a review-mode key, this test can run the review projection instead of the ship flow. DeleteDEVKIT_RUN_MODE,DEVKIT_REVIEW_ASSET_ROOT, andDEVKIT_REVIEW_PROGRESSfromenvbefore invoking the script.Based on learnings, commit/ship mode requires the absence of these three environment keys.
Proposed fix
const env = { ...process.env, ...GENV }; + delete env.DEVKIT_RUN_MODE; + delete env.DEVKIT_REVIEW_ASSET_ROOT; + delete env.DEVKIT_REVIEW_PROGRESS;📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Learnings