mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 14:06:50 +01:00
* fix(pregate): Dart import graph and test lanes (#3285) Port of arlophoenix's #3285. The import graph reads Dart import/export/part directives and resolves package: URIs through every tracked pubspec.yaml; _test.dart files under test/ are tests. lanes runs each Dart package's selected tests from its own root with flutter test or dart test (through fvm when the package pins it). flutter/dart/melos/very_good CI jobs are lanes, and run-step test paths resolve against working-directory and literal cd. A missing Dart SDK or a .dart file outside any package leaves the lane incomplete with a fix line; device tests (integration_test/, test_driver/) are not unit lanes. Co-authored-by: arlophoenix <arlo.phoenix@gmail.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(pregate): a --base that names a commit gets a branch fix, not an impossible fetch (#3269) gstack-pregate --base <sha> refused with "fix: git fetch origin <sha> --depth=1". That fetch can never create origin/<sha>: a short SHA fails with "couldn't find remote ref", and a full SHA only reaches FETCH_HEAD. A fork clone hits the same wall with --base upstream/main. When origin/<base> does not resolve but <base> names a commit here and no local branch (a SHA, a tag, another remote's ref), the refusal now says --base takes a branch name on origin and suggests origin/HEAD's branch. A local branch, or a name that resolves nowhere, keeps the fetch fix: that is the unfetched or shallow checkout it repairs. Same code, same exit 3, and pin files are still read only from the reviewed origin/<base>. Fixes #3269 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(pregate): Django, asset and tool-config lanes; init drafts from the repo (#3266, #3267, #3268) - Django: settings modules, settings strings, include(), app migrations, admin, templates, static files and project templates get framework edges (lib/pregate/django.ts). - Assets, stylesheets and dotfile tool config take a no-tests empty lane; licence text under any name is documentation. - gstack-pregate init drafts languages, runner notes and nearest-test dependencies; never writes []. - Review fixes on the #3285 port: untracked shell scopes leave a lane unknown; Dart directives read to their semicolon; nested comments. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(pregate): init draft API is exercised directly, so init-draft.ts has a lane Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(changelog): restore the history a truncated rewrite dropped Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(pregate): outside-voice review fixes for the non-JS lanes - Tool config is an allowlist: unknown dotfiles (.rspec, .husky hooks) and stylesheets still need a lane; snapshot, golden and fixture trees and .gstack/ are never inert. - Django edges need Django evidence (manage.py or code importing django) and settings assignments in code, not strings or comments. - A cd after ||, &, control flow or braces leaves a lane unknown. - Dart directives allow metadata and quoted semicolons. - init drafts at most 256 dependencies (the schema limit); the rest are TODO. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(windows): pregate-dart and pregate-non-js join the POSIX-run pregate fixtures Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * chore: release v1.91.161.0 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: arlophoenix <arlo.phoenix@gmail.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Co-authored-by: y$un_ <forrest.sun527@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
145 lines
9.4 KiB
TypeScript
145 lines
9.4 KiB
TypeScript
/**
|
|
* Fix wave PR 5, item 10b (#3197): the pregate consumers of the working-tree
|
|
* fingerprint use lib/script-invocation.ts's `{tree}|{error}` form. A
|
|
* fingerprint failure is WTREE_UNAVAILABLE, never "origin/<base> is not a
|
|
* resolvable commit": a launch failure lists each Windows bash candidate and
|
|
* names GSTACK_GIT_BASH, a gstack-wtree exit keeps the repair it printed.
|
|
* Under --json every context refusal is one envelope on stdout with exit 3,
|
|
* sharing `ok` and `status` with the run object; GSTACK_RESULT is on stderr.
|
|
* A `--base` that names a commit here but no origin branch (#3269) gets a fix
|
|
* naming a branch, never a fetch that cannot create `origin/<base>`; a branch
|
|
* name keeps the fetch fix.
|
|
*/
|
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import { EXIT, type PregateFile } from '../lib/headless-artifacts';
|
|
import { buildContext, describeRefusal, readTestBackend, withFingerprint, wtreeRefusal } from '../lib/pregate/context';
|
|
import { verifyPregate } from '../lib/pregate/index';
|
|
import type { BashProbe } from '../lib/script-invocation';
|
|
import { cleanup, makeFixtureRepo, runBin, 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()!); });
|
|
|
|
const noBash: BashProbe = { platform: 'win32', env: {}, exists: () => false, gitExecPath: () => null, which: () => null };
|
|
const badTmp = (repo: FixtureRepo) => ({ TMPDIR: path.join(repo.root, 'no-such-tmp') });
|
|
const pregate = (repo: FixtureRepo, args: string[], env: Record<string, string> = {}) => runBin(repo, 'gstack-pregate', ['--base', 'main', ...args], env);
|
|
const lastLine = (text: string) => text.trim().split('\n').pop() ?? '';
|
|
|
|
describe('WTREE_UNAVAILABLE (lib/pregate/context.ts)', () => {
|
|
test('a launch failure (no Git Bash) refuses with each candidate and the GSTACK_GIT_BASH fix, not an unresolvable base', () => {
|
|
const repo = fixture();
|
|
const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: false, env: { ...process.env, ...repo.env }, testBackend: 'local', invocation: noBash });
|
|
expect('refused' in loaded).toBe(true);
|
|
if (!('refused' in loaded)) return;
|
|
expect(loaded.refused.code).toBe('WTREE_UNAVAILABLE');
|
|
expect(loaded.refused.message).toStartWith('gstack-wtree could not start: no Git Bash found; tried GSTACK_GIT_BASH (unset): not set; ');
|
|
expect(loaded.refused.message).toContain('install path C:/Program Files/Git/bin/bash.exe: not found');
|
|
expect(loaded.refused.message).toContain('PATH bash: not on PATH');
|
|
const r = describeRefusal(loaded.refused, 'main');
|
|
expect(r.line).not.toContain('is not a resolvable commit');
|
|
expect(r.line).toEndWith('(WTREE_UNAVAILABLE)');
|
|
expect(r.fix).toContain("export GSTACK_GIT_BASH='C:/Program Files/Git/bin/bash.exe'");
|
|
expect(r.docs).toEndWith('docs/troubleshooting.md#wtree-unavailable');
|
|
});
|
|
|
|
test('a gstack-wtree exit keeps its own repair; an exit without one names how to reproduce it', () => {
|
|
expect(wtreeRefusal({ kind: 'exit', error: 'gstack-wtree exited 1: gstack-wtree: cannot create a temp index under /x; set TMPDIR to a writable directory' }))
|
|
.toEqual({ code: 'WTREE_UNAVAILABLE', message: 'gstack-wtree exited 1: gstack-wtree: cannot create a temp index under /x', fix: 'set TMPDIR to a writable directory' });
|
|
expect(wtreeRefusal({ kind: 'exit', error: 'gstack-wtree exited 1: no stderr' }).fix).toStartWith('run bin/gstack-wtree in the repository');
|
|
});
|
|
|
|
test('the after-check fingerprint failing is incomplete with its cause, not "working tree changed"', async () => {
|
|
const repo = fixture();
|
|
const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: false, env: { ...process.env, ...repo.env }, testBackend: 'local' });
|
|
if (!('ctx' in loaded)) throw new Error(JSON.stringify(loaded.refused));
|
|
const ctx = { ...loaded.ctx, env: { ...loaded.ctx.env, ...badTmp(repo) } };
|
|
const r = await withFingerprint(ctx, 'strays', 'preflight', () => ({ id: 'strays', stage: 'preflight', status: 'pass', inputs: {} }));
|
|
expect(r.status).toBe('incomplete');
|
|
expect(r.detail).toStartWith('cannot fingerprint the working tree after the check (gstack-wtree exited 1:');
|
|
expect(r.fix).toBe('set TMPDIR to a writable directory');
|
|
});
|
|
|
|
test('verify says the tree cannot be fingerprinted instead of comparing against "unknown"', () => {
|
|
const file = { schema_version: 1, tree: 'a'.repeat(40), checks: [], requires_remote: [] } as unknown as PregateFile;
|
|
const v = verifyPregate('/nonexistent', file, { kind: 'launch', error: 'gstack-wtree could not start: no Git Bash found' });
|
|
expect(v).toMatchObject({ ok: false, code: 'PREGATE_STALE', current: false });
|
|
expect(v.message).toContain('the tree cannot be fingerprinted now (gstack-wtree could not start: no Git Bash found)');
|
|
});
|
|
|
|
test('gstack-config (test_backend) launches through the script invocation, so Windows reaches it through Git Bash', () => {
|
|
const repo = fixture();
|
|
const env = { ...process.env, ...repo.env };
|
|
expect(runBin(repo, 'gstack-config', ['set', 'test_backend', 'ubicloud']).status).toBe(0);
|
|
const bash = Bun.which('bash')!;
|
|
let resolved = 0;
|
|
const backend = readTestBackend(env, { platform: 'win32', resolve: () => { resolved += 1; return { ok: true, bash, source: 'test', tried: [] }; } });
|
|
expect(resolved).toBe(1);
|
|
expect(backend).toBe('ubicloud');
|
|
});
|
|
});
|
|
|
|
describe('gstack-pregate context refusals through the CLI', () => {
|
|
test('a gstack-wtree failure prints WTREE_UNAVAILABLE with its own fix, never "is not a resolvable commit"', () => {
|
|
const repo = fixture();
|
|
const r = pregate(repo, ['--stage', 'preflight'], badTmp(repo));
|
|
expect(r.status).toBe(EXIT.refused);
|
|
expect(r.err).not.toContain('is not a resolvable commit');
|
|
expect(lastLine(r.err)).toMatch(/^gstack-pregate: cannot fingerprint the working tree: .* \(gstack-wtree exited 1: gstack-wtree: cannot create a temp index under .*no-such-tmp\); fix: set TMPDIR to a writable directory \(WTREE_UNAVAILABLE\)$/);
|
|
expect(lastLine(r.out)).toMatch(/^GSTACK_RESULT: skill=pregate status=refused /);
|
|
});
|
|
|
|
test('--json: both refusals are one envelope on stdout (exit 3) sharing ok and status with the run object; GSTACK_RESULT goes to stderr', () => {
|
|
const repo = fixture();
|
|
const wtree = pregate(repo, ['--stage', 'preflight', '--json'], badTmp(repo));
|
|
const base = runBin(repo, 'gstack-pregate', ['--base', 'no-such-base', '--stage', 'preflight', '--json']);
|
|
const run = pregate(repo, ['--stage', 'preflight', '--only', 'strays', '--json']);
|
|
for (const r of [wtree, base]) {
|
|
expect(r.status).toBe(EXIT.refused);
|
|
expect(r.out.trim().split('\n')).toHaveLength(1);
|
|
expect(r.out).not.toContain('GSTACK_RESULT');
|
|
expect(r.err).toMatch(/^GSTACK_RESULT: skill=pregate status=refused /m);
|
|
}
|
|
const w = JSON.parse(wtree.out);
|
|
expect(Object.keys(w).sort()).toEqual(['code', 'detail', 'docs', 'fix', 'ok', 'status']);
|
|
expect(w).toMatchObject({ ok: false, status: 'refused', code: 'WTREE_UNAVAILABLE', fix: 'set TMPDIR to a writable directory' });
|
|
expect(w.detail).toMatch(/cannot create a temp index under .*no-such-tmp$/);
|
|
expect(w.docs).toEndWith('#wtree-unavailable');
|
|
const b = JSON.parse(base.out);
|
|
expect(b).toMatchObject({ ok: false, status: 'refused', code: 'POLICY_SOURCE_UNAVAILABLE', detail: 'origin/no-such-base is not a resolvable commit' });
|
|
expect(b.fix).toContain('git fetch origin no-such-base --depth=1');
|
|
expect(b.docs).toEndWith('#policy-source-unavailable');
|
|
expect(run.status).toBe(EXIT.ok);
|
|
const ok = JSON.parse(run.out);
|
|
expect(ok).toMatchObject({ ok: true, status: 'complete' });
|
|
expect(run.err).toMatch(/^GSTACK_RESULT: skill=pregate status=complete run=.*pregate\.json$/m);
|
|
expect(fs.existsSync(ok.out)).toBe(true);
|
|
});
|
|
|
|
test('a --base that names a commit here but no origin branch says to pass a branch; a branch name keeps the fetch fix (#3269)', () => {
|
|
const repo = fixture();
|
|
const sha = repo.git('rev-parse', '--short=8', 'main');
|
|
repo.git('update-ref', 'refs/remotes/upstream/main', 'main');
|
|
repo.git('branch', 'unpushed', 'main');
|
|
for (const base of [sha, 'upstream/main']) {
|
|
const r = runBin(repo, 'gstack-pregate', ['--base', base, '--stage', 'preflight', '--json']);
|
|
expect(r.status).toBe(EXIT.refused);
|
|
const b = JSON.parse(r.out);
|
|
expect(b).toMatchObject({ ok: false, status: 'refused', code: 'POLICY_SOURCE_UNAVAILABLE' });
|
|
expect(b.detail).toStartWith(`origin/${base} is not a resolvable commit`);
|
|
expect(b.detail).toContain('--base takes a branch name on origin');
|
|
expect(b.fix).toContain('--base main');
|
|
expect(b.docs).toEndWith('#policy-source-unavailable');
|
|
const line = r.err.split('\n')[0]!;
|
|
expect(line).not.toContain('git fetch');
|
|
expect(line).toContain('the reviewed pin files cannot be read');
|
|
expect(line).toEndWith(`; fix: ${b.fix} (POLICY_SOURCE_UNAVAILABLE)`);
|
|
}
|
|
const unpushed = runBin(repo, 'gstack-pregate', ['--base', 'unpushed', '--stage', 'preflight', '--json']);
|
|
expect(unpushed.status).toBe(EXIT.refused);
|
|
expect(JSON.parse(unpushed.out).fix).toContain('git fetch origin unpushed --depth=1');
|
|
});
|
|
});
|