mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-02 15:04:37 +01:00
* Eval selection exemptions, review-floor rulings and the GSTA-121 follow-ups Release metadata (NOTICE.md, LICENSE, licenses/**) no longer restores the full paid gate and ETHOS.md is registered under the two prompts that read it (#3499). docs/review-policy.md records the six finding classes #3485 and #3504 ruled below the floor and the review army's lead judgment applies the table; the floor itself is unchanged. The Windows curation moves test/pregate-remote-stamp-only.test.ts to KNOWN_WINDOWS_INCOMPATIBLE (#3485). From GSTA-121: Blast radius in docs/skills.md and the merge-ask template, the 11-digit run-id exemption from pii.phone.e164 after a run word, relative string literals as import-graph edges, and a ubi-runner pack that never tars the live .git. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes Red Team pass 1 (all below the floor): an 11-digit span with a leading 1 after a run word is a US or Chinese national number, not a run id, and reports again; ubi-runner pack removes its temporary repository when it fails and replays branch.* with remote.* so a branch's upstream resolves on the VM; the conservative-refusal example in docs/review-policy.md reads in the refusing direction; the touchfiles header names why ETHOS.md sits only under the two prompts that quote it. Step 6's selection found captain/templates/merge-ask.md as the one unknown dependency of this PR and registered captain/templates/** in FREE_ONLY_PR_FILES (#3499). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes (pass 2) The cmd_pack EXIT trap bakes the temp path in: a set -e failure unwinds the function before the trap runs and a local $tmp is unset there, so the old form leaked the snapshot. The leak test creates TMPDIR where the pack reads it and asserts the failure is the missing index. CHANGELOG examples no longer spell a full national number. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: adversarial review fixes The pack snapshot carries the index's staged blobs as a pack of their own, so a VM write-tree (gstack-wtree) can read a staged file the way the old .git tar allowed; git init runs with --template= and gc.auto=0 and a valueless remote/branch key replays as true. scripts/harness-version.json re-pins scripts/test-pr-profile.ts after the captain/templates/** entry. The run-id exemption reads the same way in the scanner and gstack-post: an 11-digit span after a run word is a run id (the leading-1 exclusion from the Red Team pass contradicted gstack-post's tested contract and the ruling that a run id is not a phone number), with the residual named in the comment, the docs and the CHANGELOG. The #3499 pins move to their own test so the boundary test stays under its default budget. Docs audit: TESTING_INTERNALS names RELEASE_METADATA_FILES and captain/templates/**, docs/captain.md names Blast radius. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes (pass 4) The pack's staged-blob list comes from the copied index, holds only blobs staged against HEAD (not every tracked blob), skips gitlinks whose commit the superproject lacks, and dies with its own message when pack-objects fails. The live-checkout test covers a gitlink entry and a valueless remote key replayed as true. CHANGELOG names the staged-blob carry. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes (pass 5) The pack's blob list is the copied index's blobs that HEAD's tree lacks, so an intent-to-add entry's empty blob and the stages of an unmerged entry travel too (the HEAD-only diff list dropped both); gitlinks still skip. The live-checkout test adds an intent-to-add entry, which the VM fsck assertion covers. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
182 lines
10 KiB
TypeScript
182 lines
10 KiB
TypeScript
/**
|
|
* Lane mapping for paths a framework puts punctuation in, and for imports
|
|
* written through a tsconfig `paths` alias. Both were `no lane` false
|
|
* negatives in a Next.js App Router repo whose tests did name the files:
|
|
* - `app/(app)/recipes/page.tsx` named in a string (readFileSync) — the
|
|
* QUOTED literal pattern stopped at `(`, so the literal never matched;
|
|
* - `app/(app)/recipes/[id]/page.tsx` imported as `@/app/(app)/recipes/[id]/page`
|
|
* — `@/…` was resolved as a repo path, so it never matched a file.
|
|
*/
|
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import { MAX_TSCONFIG_EXTENDS, buildGraph, testsFor } from '../lib/pregate/import-graph';
|
|
import { cleanup, commit, makeFixtureRepo, type FixtureRepo } from './helpers/pregate-fixture';
|
|
|
|
const repos: FixtureRepo[] = [];
|
|
const fixture = () => { const r = makeFixtureRepo(); repos.push(r); return r; };
|
|
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
|
|
|
describe('import graph: route-group / dynamic-segment paths and tsconfig path aliases', () => {
|
|
test('a repo-path literal containing ( ) [ ] maps to the file it names', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'app/(app)/recipes/page.tsx': 'export default function P() { return null }\n',
|
|
'app/(app)/recipes/[id]/page.tsx': 'export default function D() { return null }\n',
|
|
'app/[[...slug]]/page.tsx': 'export default function C() { return null }\n',
|
|
'test/pages.test.ts': "import { readFileSync } from 'node:fs';\nfor (const f of ['app/(app)/recipes/page.tsx', 'app/(app)/recipes/[id]/page.tsx', 'app/[[...slug]]/page.tsx']) readFileSync(f, 'utf8');\n",
|
|
});
|
|
const g = buildGraph(repo.work);
|
|
expect(testsFor(g, 'app/(app)/recipes/page.tsx').tests).toEqual(['test/pages.test.ts']);
|
|
expect(testsFor(g, 'app/(app)/recipes/[id]/page.tsx').tests).toEqual(['test/pages.test.ts']);
|
|
expect(testsFor(g, 'app/[[...slug]]/page.tsx').tests).toEqual(['test/pages.test.ts']);
|
|
});
|
|
|
|
test('a relative literal a test reads through new URL or readFileSync maps from the file that names it', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'ship/sections/pr-body.md.tmpl': '## Summary\n',
|
|
'ship/sections/other.md.tmpl': '## Other\n',
|
|
'docs/guide.md': '# guide\n',
|
|
'test/publication.test.ts': "import { readFileSync } from 'node:fs';\nreadFileSync(new URL('../ship/sections/pr-body.md.tmpl', import.meta.url), 'utf8');\nreadFileSync('./../docs/guide.md', 'utf8');\n",
|
|
'test/nested/deep.test.ts': "import { readFileSync } from 'node:fs';\nreadFileSync('../../ship/sections/other.md.tmpl', 'utf8');\n",
|
|
});
|
|
const g = buildGraph(repo.work);
|
|
expect(testsFor(g, 'ship/sections/pr-body.md.tmpl').tests).toEqual(['test/publication.test.ts']);
|
|
expect(testsFor(g, 'docs/guide.md').tests).toEqual(['test/publication.test.ts']);
|
|
expect(testsFor(g, 'ship/sections/other.md.tmpl').tests).toEqual(['test/nested/deep.test.ts']);
|
|
// A relative literal that climbs out of the repository names nothing.
|
|
commit(repo, { 'test/escape.test.ts': "import { readFileSync } from 'node:fs';\nreadFileSync('../../../ship/sections/pr-body.md.tmpl', 'utf8');\n" });
|
|
expect(testsFor(buildGraph(repo.work), 'ship/sections/pr-body.md.tmpl').tests).toEqual(['test/publication.test.ts']);
|
|
});
|
|
|
|
test('a relative import of a bracketed path already maps (control: the import scanner is not the bug)', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'app/(app)/recipes/[id]/page.tsx': 'export default function D() { return null }\n',
|
|
'test/detail.test.tsx': "import D from '../app/(app)/recipes/[id]/page';\nD();\n",
|
|
});
|
|
expect(testsFor(buildGraph(repo.work), 'app/(app)/recipes/[id]/page.tsx').tests).toEqual(['test/detail.test.tsx']);
|
|
});
|
|
|
|
test('an import through a tsconfig paths alias (JSONC, with comments and a trailing comma) maps; so does a vi.mock of it', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': '{\n // Next.js default\n "compilerOptions": {\n "baseUrl": ".",\n "paths": { "@/*": ["./*"], "~lib/*": ["lib/*"], },\n },\n}\n',
|
|
'app/(app)/recipes/[id]/page.tsx': 'export default function D() { return null }\n',
|
|
'lib/plan.ts': 'export const plan = 1;\n',
|
|
'lib/mocked.ts': 'export const m = 1;\n',
|
|
'test/detail.test.tsx': "import D from '@/app/(app)/recipes/[id]/page';\nimport { plan } from '~lib/plan';\nvi.mock('@/lib/mocked', () => ({}));\nD(); plan;\n",
|
|
});
|
|
const g = buildGraph(repo.work);
|
|
expect(testsFor(g, 'app/(app)/recipes/[id]/page.tsx').tests).toEqual(['test/detail.test.tsx']);
|
|
expect(testsFor(g, 'lib/plan.ts').tests).toEqual(['test/detail.test.tsx']);
|
|
expect(testsFor(g, 'lib/mocked.ts').tests).toEqual(['test/detail.test.tsx']);
|
|
});
|
|
|
|
test('without a tsconfig an @scope/pkg import still resolves to nothing (no new false edges)', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'lib/plan.ts': 'export const plan = 1;\n',
|
|
'test/scoped.test.ts': "import { x } from '@scope/plan';\nx;\n",
|
|
});
|
|
expect(testsFor(buildGraph(repo.work), 'lib/plan.ts').tests).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('import graph: alias precedence, extends and the no-lane explanation', () => {
|
|
const twoAliases = (specificFirst: boolean) => {
|
|
const specific = '"@/lib/*": ["src/lib/*"]';
|
|
const broad = '"@/*": ["./*"]';
|
|
return `{ "compilerOptions": { "paths": { ${specificFirst ? `${specific}, ${broad}` : `${broad}, ${specific}`} } } }\n`;
|
|
};
|
|
|
|
for (const specificFirst of [true, false]) {
|
|
test(`overlapping aliases pick the most specific pattern when both targets exist (${specificFirst ? 'specific' : 'broad'} key first)`, () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': twoAliases(specificFirst),
|
|
'lib/x.ts': 'export const x = "root";\n',
|
|
'src/lib/x.ts': 'export const x = "src";\n',
|
|
'test/x.test.ts': "import { x } from '@/lib/x';\nx;\n",
|
|
});
|
|
const g = buildGraph(repo.work);
|
|
expect(testsFor(g, 'src/lib/x.ts').tests).toEqual(['test/x.test.ts']);
|
|
expect(testsFor(g, 'lib/x.ts').tests).toEqual([]);
|
|
});
|
|
}
|
|
|
|
test('an exact alias wins over a wildcard that also matches', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': '{ "compilerOptions": { "paths": { "@/*": ["./*"], "@/env": ["src/env.ts"] } } }\n',
|
|
'env.ts': 'export const env = 1;\n',
|
|
'src/env.ts': 'export const env = 2;\n',
|
|
'test/env.test.ts': "import { env } from '@/env';\nenv;\n",
|
|
});
|
|
const g = buildGraph(repo.work);
|
|
expect(testsFor(g, 'src/env.ts').tests).toEqual(['test/env.test.ts']);
|
|
expect(testsFor(g, 'env.ts').tests).toEqual([]);
|
|
});
|
|
|
|
test('a later target is the fallback when the first target does not exist', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': '{ "compilerOptions": { "paths": { "@/*": ["src/*", "generated/*"] } } }\n',
|
|
'generated/api.ts': 'export const api = 1;\n',
|
|
'test/api.test.ts': "import { api } from '@/api';\napi;\n",
|
|
});
|
|
expect(testsFor(buildGraph(repo.work), 'generated/api.ts').tests).toEqual(['test/api.test.ts']);
|
|
});
|
|
|
|
test('when the chosen alias resolves nothing, every plausible reading gains the edge (uncertainty selects more)', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': '{ "compilerOptions": { "paths": { "@/ui/*": ["packages/ui/*"], "@/*": ["src/*"] } } }\n',
|
|
'src/ui/button.ts': 'export const b = 1;\n',
|
|
'test/button.test.ts': "import { b } from '@/ui/button';\nb;\n",
|
|
});
|
|
expect(testsFor(buildGraph(repo.work), 'src/ui/button.ts').tests).toEqual(['test/button.test.ts']);
|
|
});
|
|
|
|
test('a relative extends chain supplies paths and baseUrl relative to the config that declares them', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': '{ "extends": "./config/tsconfig.base", "compilerOptions": { "strict": true } }\n',
|
|
'config/tsconfig.base.json': '{ "extends": "./tsconfig.paths.json" }\n',
|
|
'config/tsconfig.paths.json': '{ "compilerOptions": { "baseUrl": "..", "paths": { "#lib/*": ["lib/*"] } } }\n',
|
|
'lib/plan.ts': 'export const plan = 1;\n',
|
|
'test/plan.test.ts': "import { plan } from '#lib/plan';\nplan;\n",
|
|
});
|
|
expect(testsFor(buildGraph(repo.work), 'lib/plan.ts').tests).toEqual(['test/plan.test.ts']);
|
|
});
|
|
|
|
test('trailing commas are dropped by the tokenizer, never inside a string', () => {
|
|
const repo = fixture();
|
|
commit(repo, {
|
|
'tsconfig.json': '{ "compilerOptions": { "paths": { "~a,]/*": ["lib/*",], }, }, }\n',
|
|
'lib/plan.ts': 'export const plan = 1;\n',
|
|
'test/plan.test.ts': "import { plan } from '~a,]/plan';\nplan;\n",
|
|
});
|
|
expect(testsFor(buildGraph(repo.work), 'lib/plan.ts').tests).toEqual(['test/plan.test.ts']);
|
|
});
|
|
|
|
test('an extends chain past the depth limit is named in the no-lane explanation, with the unresolved specifiers', () => {
|
|
const repo = fixture();
|
|
const files: Record<string, string> = {
|
|
'tsconfig.json': '{ "extends": "./c1.json" }\n',
|
|
'lib/plan.ts': 'export const plan = 1;\n',
|
|
'test/plan.test.ts': "import { plan } from '#lib/plan';\nimport { gone } from '../lib/gone';\nimport { expect } from 'bun:test';\nimport React from 'react';\nplan; gone; expect; React;\n",
|
|
};
|
|
for (let i = 1; i <= MAX_TSCONFIG_EXTENDS; i++) files[`c${i}.json`] = `{ "extends": "./c${i + 1}.json" }\n`;
|
|
files[`c${MAX_TSCONFIG_EXTENDS + 1}.json`] = '{ "compilerOptions": { "paths": { "#lib/*": ["lib/*"] } } }\n';
|
|
commit(repo, files);
|
|
const m = testsFor(buildGraph(repo.work), 'lib/plan.ts');
|
|
expect(m.tests).toEqual([]);
|
|
const text = m.provenance.join('\n');
|
|
expect(text).toContain(`tsconfig extends depth limit ${MAX_TSCONFIG_EXTENDS}`);
|
|
expect(text).toContain("test/plan.test.ts: '#lib/plan' '../lib/gone'");
|
|
expect(text).not.toContain("'react'");
|
|
expect(text).not.toContain("'bun:test'");
|
|
expect(text).toContain('declare the file under dependencies in .gstack/pregate.json, or report the resolver gap');
|
|
});
|
|
});
|