mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-24 09:01:28 +01:00
Review keeps a file that a branch swaps from our own code to upstream bytes (GST-3298) (#4690)
A branch that replaces your own file, or drops a local patch, so the file now matches an upstream copy byte for byte no longer leaves review: a changed file counts as vendored only if it was already vendored and verified at the merge base, or is new on the branch. This closes the gap the second-model review of #4665 found, so readers always see your own lines leave. Nothing to do for repos without `review_vendored`, which is every repo today. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/outside-voice#2 reader=outside-voice Review-Finding: p1/red-team#1 reader=red-team
This commit is contained in:
1 parent
3759f657f7
commit
3cff6a47f6
7 files changed
+239
-43
No files matched your search
@@ -10,6 +10,7 @@ import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { disclosureLine } from '../lib/review-exclude';
|
||||
import { vendoredCacheRoot, vendoredPolicy, vendoredSelection } from '../lib/review-vendored';
|
||||
import { receiptReviewAtHead } from '../lib/ship-receipt-depth';
|
||||
import { REVIEW_VENDORED_KEY_VERSION } from '../lib/ship-policy';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
@@ -149,6 +150,46 @@ describe('review_exclude_paths with review_vendored', () => {
|
||||
expect(x.vendored_selection.verified).toEqual([]);
|
||||
});
|
||||
|
||||
// Value: protects=a branch that replaces our own file, or a locally patched vendored file, with verified upstream bytes
|
||||
// keeps that file in review as code, so readers see our lines leave; a file new on the branch, or vendored at the merge
|
||||
// base too (the re-pin test above), still leaves the diff; fails_when=a modified file is checked at the head only;
|
||||
// why_new=/ship review of #4665 (outside-voice finding lib/review-vendored.ts:319), GST-3298 PR 3
|
||||
test('a branch that swaps our own file or a local patch for upstream bytes keeps it in review', () => {
|
||||
const ours = fixture();
|
||||
ours.repo.git('checkout', '-q', 'main');
|
||||
commit(ours.repo, local({ 'tests/a.py': 'def test_a():\n assert check_signature()\n' }), 'our own test');
|
||||
ours.repo.git('push', '-q', 'origin', 'main');
|
||||
ours.repo.git('checkout', '-q', '-B', 'feat');
|
||||
commit(ours.repo, { ...local({ 'tests/a.py': A, 'tests/c.py': C }), 'VENDORED.json': manifest(ours.up.c2, ['tests/a.py', 'tests/c.py']) }, 'vendor lib over our test');
|
||||
expect(ours.plan(false).out).toContain('REVIEW_VENDORED_KEPT: mismatched up/lib/tests/a.py (the merge base has this file but its manifests do not pin it');
|
||||
const x = JSON.parse(ours.plan(true).out).review_exclude;
|
||||
expect({ kept: x.kept_files, verified: x.vendored_selection.verified }).toEqual({ kept: [{ path: 'up/lib/tests/a.py', reason: 'code' }], verified: ['up/lib/tests/c.py'] });
|
||||
const patched = fixture();
|
||||
patched.repo.git('checkout', '-q', 'main');
|
||||
commit(patched.repo, { ...local({ 'tests/b.py': B1 + 'assert local_patch()\n' }), 'VENDORED.json': manifest(patched.up.c1, ['tests/b.py']) }, 'vendor lib with a local patch');
|
||||
patched.repo.git('push', '-q', 'origin', 'main');
|
||||
patched.repo.git('checkout', '-q', '-B', 'feat');
|
||||
commit(patched.repo, local({ 'tests/b.py': B1 }), 'drop the local patch');
|
||||
expect(patched.plan(false).out).toContain("REVIEW_VENDORED_KEPT: mismatched up/lib/tests/b.py (its merge-base copy is not the upstream's file (mismatched");
|
||||
expect(keptOf(patched.plan(true).out)).toEqual([{ path: 'up/lib/tests/b.py', reason: 'code' }]);
|
||||
});
|
||||
|
||||
// Value: protects=a working-tree edit to a verified vendored file keeps it in review on a live-tree plan; fails_when=the
|
||||
// committed blob's verdict covers uncommitted bytes; why_new=/ship review of #4665 (test gap lib/review-vendored.ts:330)
|
||||
test('a working-tree edit to a verified vendored file keeps it in review', () => {
|
||||
const f = fixture();
|
||||
commit(f.repo, { ...local({ 'tests/a.py': A, 'tests/b.py': B1 }), 'VENDORED.json': manifest(f.up.c1, ['tests/a.py', 'tests/b.py']) }, 'vendor lib');
|
||||
fs.writeFileSync(path.join(f.repo.work, 'up/lib/tests/b.py'), B1 + 'assert edited()\n');
|
||||
const mergeBase = f.repo.git('merge-base', 'origin/main', 'HEAD').trim();
|
||||
const sel = vendoredSelection({
|
||||
root: f.repo.work, policy: vendoredPolicy(JSON.parse(policy()))!, mergeBase, changed: new Set(['up/lib/tests/a.py', 'up/lib/tests/b.py', 'VENDORED.json']), fetch: true,
|
||||
cacheRoot: vendoredCacheRoot(f.repo.env.GSTACK_STATE_ROOT), env: { ...process.env, ...f.repo.env, GSTACK_VENDORED_FETCH_ROOT: f.up.fetchRoot },
|
||||
});
|
||||
if ('error' in sel) throw new Error(sel.error);
|
||||
expect(sel.verified).toEqual(['up/lib/tests/a.py']);
|
||||
expect(sel.failed.map(e => [e.path, e.verdict, e.detail])).toEqual([['up/lib/tests/b.py', 'mismatched', 'changed in the working tree']]);
|
||||
});
|
||||
|
||||
// Value: protects=a manifest under an applied pattern turns the vendored check off, so the files it pins stay in review
|
||||
// whole and a hidden re-pin cannot hide them too; fails_when=files verify against a manifest readers cannot see;
|
||||
// why_new=/ship review of #4665 (red-team finding lib/review-exclude.ts:483)
|
||||
@@ -169,6 +210,7 @@ describe('review_exclude_paths with review_vendored', () => {
|
||||
expect(x.kept_files).toEqual([{ path: 'up/lib/tests/data.json', reason: 'named-by-code' }]);
|
||||
expect(x.vendored).toBe(1);
|
||||
expect(disclosureLine(x)).toContain(' 1 of the excluded files are vendored upstream files');
|
||||
expect(disclosureLine(x)).not.toContain('is in your diff');
|
||||
});
|
||||
|
||||
// Value: protects=a repo without review_vendored plans exactly as before: the same files kept as code, no vendored line and
|
||||
@@ -184,8 +226,9 @@ describe('review_exclude_paths with review_vendored', () => {
|
||||
expect(x.vendored_selection).toBeUndefined();
|
||||
});
|
||||
|
||||
// Value: protects=too many unverified vendored files refuse with a fix that names REVIEW_VENDORED_KEPT and the verify
|
||||
// command instead of the review_content_patterns fix; fails_when=the old fix is printed; why_new=GST-3298 plan F1
|
||||
// Value: protects=too many unverified vendored files refuse with a fix that names the verify command, never lines a
|
||||
// refused plan does not print, and a vendored check that could not run says so instead of counting every kept file as
|
||||
// vendored; fails_when=the old fix is printed; why_new=GST-3298 plan F1, /ship review of #4665 (lib/review-exclude.ts:524)
|
||||
test('a keep-too-large refusal over unverified vendored files names the verify command', () => {
|
||||
const f = fixture();
|
||||
const many: Record<string, string> = {};
|
||||
@@ -194,6 +237,12 @@ describe('review_exclude_paths with review_vendored', () => {
|
||||
commit(f.repo, { ...local({ ...many, 'tests/a.py': A }), 'VENDORED.json': manifest(f.up.c1, [...names, 'tests/a.py']) }, 'vendor lib');
|
||||
const r = f.plan(false);
|
||||
expect(r.out + r.err).toContain('REVIEW_EXCLUDE_KEEP_TOO_LARGE');
|
||||
expect(r.out + r.err).toContain('330 of them are vendored files that did not verify (gstack-review-plan lists them as REVIEW_VENDORED_KEPT); run gstack-vendored-verify --base main');
|
||||
expect(r.out + r.err).toContain('330 of them are manifest entries that do not count as vendored (they did not verify, or the merge base has them as our own code); run gstack-vendored-verify --base main');
|
||||
expect(r.out + r.err).not.toContain('REVIEW_VENDORED_KEPT');
|
||||
const hidden = fixture(true, 'up/VENDORED.json');
|
||||
commit(hidden.repo, { ...local(many), 'up/VENDORED.json': manifest(hidden.up.c1, names) }, 'vendor lib');
|
||||
const h = hidden.plan(false);
|
||||
expect(h.out + h.err).toContain('the vendored check could not run (up/VENDORED.json matches review_exclude_paths');
|
||||
expect(h.out + h.err).not.toContain('of them are manifest entries');
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,7 @@ import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { bunIsolationArgs } from '../lib/bun-isolation';
|
||||
import { REVIEW_VENDORED_KEY_VERSION, finish } from '../lib/ship-policy';
|
||||
import { parseManifest, pathProblem, vendoredErrors } from '../lib/review-vendored';
|
||||
import { parseManifest, pathProblem, vendoredCacheRoot, vendoredErrors, vendoredPolicy, vendoredSelection } from '../lib/review-vendored';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
setDefaultTimeout(60_000);
|
||||
@@ -268,6 +268,91 @@ describe('branch globs, missing branches, gitlinks and --json', () => {
|
||||
expect(outOf(m)).toContain('reachable_from=heads/release/2');
|
||||
expect(m.status).toBe(0);
|
||||
});
|
||||
// Value: protects=a branch the upstream deletes stops vouching for its commits: the cached ref goes, online and then
|
||||
// offline; fails_when=a stale cached branch keeps a commit reachable; why_new=/ship review of #4665 (test gap
|
||||
// lib/review-vendored.ts:207 for the update-ref -d cleanup)
|
||||
test('a named branch the upstream deletes drops its cached ref, online and offline', () => {
|
||||
const c = consumer({ policy: policy([{ url: UP, branches: ['release/2'] }]) });
|
||||
commit(c.repo, { 'vendor/lib/tests/a.py': A + '# rel\n', 'vendor/MANIFEST.json': manifest([{ commit: c.up.release, files: ['tests/a.py'] }]) }, 'pin');
|
||||
expect(outOf(c.verify())).toContain('reachable_from=heads/release/2');
|
||||
run(c.up.work, ['push', '-q', c.up.bare, ':refs/heads/release/2'], c.upEnv);
|
||||
for (const args of [['--base', 'main'], ['--base', 'main', '--offline']]) {
|
||||
const r = c.verify(args);
|
||||
expect(outOf(r)).toContain('(VENDORED_UNREACHABLE)');
|
||||
expect(r.status).toBe(1);
|
||||
}
|
||||
});
|
||||
// Value: protects=a fetch that fails after a good one fails this run but leaves the good cached pins, so a later offline
|
||||
// check still answers; fails_when=the failure overwrites the cache; why_new=/ship review of #4665 (deferred finding
|
||||
// lib/review-vendored.ts:201)
|
||||
test('a failed fetch fails its own run and keeps the good cached pins', () => {
|
||||
const c = consumer();
|
||||
expect(c.verify().status).toBe(0);
|
||||
fs.renameSync(c.up.bare, `${c.up.bare}.away`);
|
||||
const down = c.verify();
|
||||
expect(outOf(down)).toContain('(VENDORED_FETCH_FAILED)');
|
||||
expect(down.status).toBe(1);
|
||||
const offline = c.verify(['--base', 'main', '--offline']);
|
||||
expect(outOf(offline)).toMatch(/checked=2 verified=2 failed=0/);
|
||||
expect(offline.status).toBe(0);
|
||||
});
|
||||
// Value: protects=after a failed fetch the review plan and every later offline step select the same files, so the
|
||||
// receipt's offline recompute matches the plan's digest, while gstack-vendored-verify --offline still answers from the
|
||||
// good pins; fails_when=the offline selection counts a file the plan kept; why_new=/ship review of #4690
|
||||
// (lib/review-vendored.ts:278)
|
||||
test('after a failed fetch the online and offline selections agree until a fetch succeeds', () => {
|
||||
const c = consumer();
|
||||
expect(c.verify().status).toBe(0);
|
||||
const both = ['vendor/lib/tests/a.py', 'vendor/lib/tests/b.py'];
|
||||
const select = (fetch: boolean) => {
|
||||
const sel = vendoredSelection({ root: c.repo.work, policy: vendoredPolicy(JSON.parse(policy()))!, head: c.repo.git('rev-parse', 'HEAD').trim(), mergeBase: c.repo.git('merge-base', 'origin/main', 'HEAD').trim(), changed: new Set(both), fetch, cacheRoot: vendoredCacheRoot(c.repo.env.GSTACK_STATE_ROOT), env: { ...process.env, ...c.repo.env, GSTACK_VENDORED_FETCH_ROOT: c.fetchRoot } });
|
||||
return 'error' in sel ? sel.error : sel.verified;
|
||||
};
|
||||
fs.renameSync(c.up.bare, `${c.up.bare}.away`);
|
||||
expect(select(true)).toEqual([]);
|
||||
expect(select(false)).toEqual([]);
|
||||
expect(c.verify(['--base', 'main', '--offline']).status).toBe(0);
|
||||
fs.renameSync(`${c.up.bare}.away`, c.up.bare);
|
||||
expect(select(true)).toEqual(both);
|
||||
expect(select(false)).toEqual(both);
|
||||
});
|
||||
// Value: protects=the merge-base pin check never fails verify, even when it throws: a deletion-only re-pin whose old pin
|
||||
// cannot be cached still passes on its head result; fails_when=the base check's error exits nonzero; why_new=/ship review
|
||||
// of #4690 (bin/gstack-vendored-verify:88)
|
||||
test('a merge-base check that cannot run reports itself and leaves the head verdict alone', () => {
|
||||
const c = consumer();
|
||||
c.repo.git('checkout', '-q', 'main');
|
||||
c.repo.git('merge', '-q', '--ff-only', 'feat');
|
||||
c.repo.git('push', '-q', 'origin', 'main');
|
||||
c.repo.git('checkout', '-q', 'feat');
|
||||
commit(c.repo, { 'vendor/lib/tests/b.py': null, 'vendor/MANIFEST.json': manifest([{ commit: c.up.c1, files: ['tests/a.py'] }]) }, 'drop b');
|
||||
const blocked = path.join(c.repo.root, 'blocked');
|
||||
fs.mkdirSync(blocked);
|
||||
fs.writeFileSync(path.join(blocked, 'vendored-cache'), 'not a directory\n');
|
||||
const r = c.verify(['--base', 'main'], { GSTACK_STATE_ROOT: blocked, GSTACK_HOME: blocked, GSTACK_STATE_DIR: blocked });
|
||||
expect(outOf(r)).toContain('VENDORED_BASE: unavailable (');
|
||||
expect(outOf(r)).toContain('VENDORED_VERIFY: checked=0 verified=0 failed=0');
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
// Value: protects=verify also caches the merge base's pin for a re-pinned file, so the review plan answers offline on a
|
||||
// clean machine and keeps treating the file as vendored; fails_when=the old pin stays cold and the offline selection
|
||||
// keeps the file; why_new=GST-3298 PR 3 (a modified file counts only when its base copy verified)
|
||||
test('verify caches the merge base pins a re-pin needs for an offline selection', () => {
|
||||
const c = consumer();
|
||||
c.repo.git('checkout', '-q', 'main');
|
||||
c.repo.git('merge', '-q', '--ff-only', 'feat');
|
||||
c.repo.git('push', '-q', 'origin', 'main');
|
||||
c.repo.git('checkout', '-q', 'feat');
|
||||
commit(c.repo, { 'vendor/lib/tests/b.py': B2, 'vendor/MANIFEST.json': manifest([{ commit: c.up.c2, files: ['tests/a.py', 'tests/b.py'] }]) }, 'repin');
|
||||
const cold = path.join(c.repo.root, 'cold');
|
||||
const coldEnv = { GSTACK_STATE_ROOT: cold, GSTACK_HOME: cold, GSTACK_STATE_DIR: cold };
|
||||
const r = c.verify(['--base', 'main'], coldEnv);
|
||||
expect(outOf(r)).toContain('VENDORED_BASE: checked=1 verified=1');
|
||||
expect(r.status).toBe(0);
|
||||
const mergeBase = c.repo.git('merge-base', 'origin/main', 'HEAD').trim();
|
||||
const sel = vendoredSelection({ root: c.repo.work, policy: vendoredPolicy(JSON.parse(policy()))!, head: c.repo.git('rev-parse', 'HEAD').trim(), mergeBase, changed: new Set(['vendor/lib/tests/b.py']), fetch: false, cacheRoot: vendoredCacheRoot(cold) });
|
||||
expect('error' in sel ? sel.error : sel.verified).toEqual(['vendor/lib/tests/b.py']);
|
||||
});
|
||||
test('an upstream gitlink is VENDORED_MODE, and --json keeps the pin count beside the pin rows', () => {
|
||||
const c = consumer();
|
||||
run(c.up.work, ['update-index', '--add', '--cacheinfo', `160000,${c.up.c1},tests/sub`], c.upEnv);
|
||||
|
||||
Reference in new issue
Block a user