mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 17:41:35 +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
+22
-11
@@ -8,7 +8,9 @@
|
||||
* The allowlist and the manifest list come from the base branch's .gstack/ship-policy.json (review_vendored), never
|
||||
* from the head; the manifests themselves are read at HEAD. By default it checks the entries this branch changes
|
||||
* (files added, modified or deleted since the merge base, and entries whose pin the manifest diff changes); --all checks every
|
||||
* entry. --offline answers from the cache an earlier run filled, without the network. A repo makes it a required CI
|
||||
* entry. --offline answers from the cache an earlier run filled, without the network. It also checks the merge base's
|
||||
* pins for the files this branch changes or deletes (VENDORED_BASE), so the review plan can answer offline for a modified
|
||||
* or re-pinned file; that line never fails the run. A repo makes it a required CI
|
||||
* check: exit 1 means a manifest says something that is not true. Logic: lib/review-vendored.ts.
|
||||
*/
|
||||
import { spawnSync } from '../lib/spawn-sync';
|
||||
@@ -62,6 +64,7 @@ if (!policy) { process.stdout.write(json ? JSON.stringify({ state: 'none' }) + '
|
||||
const problems: string[] = [];
|
||||
const entries: VendoredEntry[] = [];
|
||||
const before = new Map<string, string>();
|
||||
const prior: VendoredEntry[] = [];
|
||||
for (const m of policy.manifests) {
|
||||
const text = git(['show', `${head}:${m}`]);
|
||||
if (text === null) { problems.push(`${m} is not in HEAD`); continue; }
|
||||
@@ -69,30 +72,38 @@ for (const m of policy.manifests) {
|
||||
problems.push(...parsed.errors);
|
||||
entries.push(...parsed.entries);
|
||||
const old = git(['show', `${mergeBase}:${m}`]);
|
||||
if (old !== null) for (const e of parseManifest(old, m).entries) before.set(e.path, `${e.upstream}@${e.commit}:${e.upstream_path}`);
|
||||
if (old !== null) for (const e of parseManifest(old, m).entries) { before.set(e.path, `${e.upstream}@${e.commit}:${e.upstream_path}`); prior.push(e); }
|
||||
}
|
||||
const seen = new Map<string, number>();
|
||||
entries.forEach(e => seen.set(e.path.toLowerCase(), (seen.get(e.path.toLowerCase()) ?? 0) + 1));
|
||||
for (const [p, n] of seen) if (n > 1) problems.push(`${p} is pinned by more than one manifest`);
|
||||
|
||||
let selected = entries;
|
||||
if (!argv.includes('--all')) {
|
||||
const diff = git(['diff', '--name-only', '-z', '--no-renames', '--diff-filter=ADMT', mergeBase, head]);
|
||||
if (diff === null) { process.stderr.write(`${CTX}: git could not list the files this branch changes; fix: rerun once, then check the checkout (git status)\n`); process.exit(EXIT.refused); }
|
||||
const changed = new Set(diff.split('\0').filter(Boolean));
|
||||
selected = entries.filter(e => changed.has(e.path) || before.get(e.path) !== `${e.upstream}@${e.commit}:${e.upstream_path}`);
|
||||
}
|
||||
const res = problems.length ? null : resolveVendored({ root, rev: head, policy, entries: selected, fetch: !argv.includes('--offline'), cacheRoot: vendoredCacheRoot(resolveStateRoot()) });
|
||||
const diff = git(['diff', '--name-only', '-z', '--no-renames', '--diff-filter=ADMT', mergeBase, head]);
|
||||
if (diff === null) { process.stderr.write(`${CTX}: git could not list the files this branch changes; fix: rerun once, then check the checkout (git status)\n`); process.exit(EXIT.refused); }
|
||||
const changed = new Set(diff.split('\0').filter(Boolean));
|
||||
const selected = argv.includes('--all') ? entries : entries.filter(e => changed.has(e.path) || before.get(e.path) !== `${e.upstream}@${e.commit}:${e.upstream_path}`);
|
||||
const resolve = (rev: string, list: VendoredEntry[]) => resolveVendored({ root, rev, policy, entries: list, fetch: !argv.includes('--offline'), cacheRoot: vendoredCacheRoot(resolveStateRoot()), keepGood: true });
|
||||
const res = problems.length ? null : resolve(head, selected);
|
||||
const baseList = prior.filter(e => changed.has(e.path));
|
||||
const baseSummary = ((): { checked: number; verified: number } | { error: string } | null => {
|
||||
if (!res || !baseList.length) return null;
|
||||
try {
|
||||
const b = resolve(mergeBase, baseList);
|
||||
return b ? { checked: b.entries.length, verified: b.entries.filter(e => e.verdict === 'verified').length } : null;
|
||||
} catch (err) { return { error: (err instanceof Error ? err.message : String(err)).split('\n')[0]! }; }
|
||||
})();
|
||||
if (!problems.length && !res) { process.stderr.write(`${CTX}: git could not list HEAD's files; fix: rerun once, then check the checkout (git status)\n`); process.exit(EXIT.refused); }
|
||||
const failed = res?.entries.filter(e => e.verdict !== 'verified') ?? [];
|
||||
const summary = { scope: argv.includes('--all') ? 'all' : 'changed', manifests: policy.manifests.length, entries: entries.length, checked: res?.entries.length ?? 0, verified: (res?.entries.length ?? 0) - failed.length, failed: failed.length, pins: res?.pins.length ?? 0, digest: res?.digest ?? null };
|
||||
if (json) {
|
||||
process.stdout.write(JSON.stringify({ state: problems.length || failed.length ? 'failed' : 'verified', ...summary, manifest_errors: problems, pin_results: res?.pins ?? [], failures: failed }) + '\n');
|
||||
process.stdout.write(JSON.stringify({ state: problems.length || failed.length ? 'failed' : 'verified', ...summary, manifest_errors: problems, pin_results: res?.pins ?? [], failures: failed, ...(baseSummary ? { base: baseSummary } : {}) }) + '\n');
|
||||
} else {
|
||||
for (const p of problems) process.stdout.write(resultLine(CTX, 'VENDORED_MANIFEST_INVALID', p) + '\n');
|
||||
for (const p of res?.pins ?? []) process.stdout.write(`VENDORED_PIN: ${p.upstream}@${p.commit.slice(0, 12)} reachable_from=${p.reachable_from ?? 'none'} files=${p.files} verified=${p.verified}\n`);
|
||||
for (const f of failed.slice(0, 50)) process.stdout.write(resultLine(CTX, CODES[f.verdict as Exclude<VendoredVerdict, 'verified'>], `${f.path} <- ${f.upstream}@${f.commit.slice(0, 12)}:${f.upstream_path}${f.detail ? `; ${f.detail}` : ''}`) + '\n');
|
||||
if (failed.length > 50) process.stdout.write(`VENDORED_VERIFY_FAILED: +${failed.length - 50} more (--json lists every one)\n`);
|
||||
if (baseSummary && 'error' in baseSummary) process.stdout.write(`VENDORED_BASE: unavailable (${baseSummary.error}; this line never fails the run)\n`);
|
||||
else if (baseSummary) process.stdout.write(`VENDORED_BASE: checked=${baseSummary.checked} verified=${baseSummary.verified} (the merge base's copies of the vendored files this branch changes or deletes; the review plan treats a modified file as vendored only when its base copy verified; this line never fails the run)\n`);
|
||||
process.stdout.write(problems.length ? `VENDORED_VERIFY: failed manifests=${policy.manifests.length} manifest_errors=${problems.length}\n`
|
||||
: `VENDORED_VERIFY: checked=${summary.checked} verified=${summary.verified} failed=${summary.failed} pins=${summary.pins} manifests=${summary.manifests} scope=${summary.scope} digest=${summary.digest}\n`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user