Files
gstack/test/frontend-scope.test.ts
T
Garry TanandClaude Fable 5.1 9a03aa5e4a test: touchfiles, tiers, shim E2E, real-engine fixture
Touchfiles: the catalog, contract, detector bin, checklist resolver, review-
army resolver, and DESIGN.md lib join the dep lists of review-design-lite,
design-review-fix, the design-consultation cases, and plan-design-review-no-
ui-scope, so editing any of them re-selects the tests that read their output.
Three new E2E keys: design-review-detector-shim (gate; source mode on a
feature-branch diff), design-review-detector-shim-dom (gate; DOM mode: the
slop fixture served on loopback, dumped through the browse binary with
lib/dom-dump.js, persisted under a GSTACK_HOME-scoped REPORT_DIR, scanned once;
self-skips when browse/dist/browse is absent), and design-html-slop-gate
(periodic; one fix pass, at most two scans, remaining findings accepted with
reason). Every case reaches the engine through test/fixtures/fake-impeccable.ts
via IMPECCABLE_BIN from outside the temp repo, reads extracted skill sections
(never a whole SKILL.md) with the installed bin path rewritten to this
checkout, and asserts the probe ran, the right scan verb ran, `npx impeccable`
never did, and the output carries FINDING rows tagged [ai-color-palette] and
[low-contrast]. review-design-lite gets the fake engine and an eighth tally
signal for a detector row; its 4-hit threshold is unchanged.

test/gstack-design-detect.test.ts evaluates design-review's REPORT_DIR
expression with GSTACK_HOME set and proves a dump under it is accepted by the
wrapper's allow-list. The sample fixtures were real captures from commit 1
(engine 0.1.3), so there is nothing hand-written left to swap.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-08 16:38:46 +00:00

87 lines
3.2 KiB
TypeScript

/**
* lib/frontend-scope.ts mirrors the m_frontend arm of bin/gstack-diff-scope.
* Pure cases run everywhere; the parity case runs the bash script in a temp
* repo (POSIX only) so the two implementations cannot drift silently.
*/
import { describe, test, expect } from 'bun:test';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { spawnSync } from 'child_process';
import { isFrontendPath } from '../lib/frontend-scope';
const ROOT = path.join(import.meta.dir, '..');
const POSIX = process.platform !== 'win32';
const SAMPLES: Array<[string, boolean]> = [
['src/components/Button.tsx', true],
['src/Button.jsx', true],
['pages/index.vue', true],
['app/Widget.svelte', true],
['site/page.astro', true],
['styles/main.css', true],
['css/a.scss', true],
['x/y/theme.less', true],
['x/a.sass', true],
['x/a.pcss', true],
['app/views/users/show.html.erb', true],
['templates/a.haml', true],
['templates/a.slim', true],
['templates/a.hbs', true],
['views/a.ejs', true],
['public/index.html', true],
['tailwind.config.js', true],
['postcss.config.cjs', true],
['app/assets/stylesheets/app.css', true],
['lib/util/components/helper.rb', true],
['lib/server.ts', false],
['src/api/route.js', false],
['README.md', false],
['package.json', false],
['test/foo.test.ts', false],
['components.md', false],
];
describe('isFrontendPath', () => {
test.each(SAMPLES)('%s → %p', (p, expected) => {
expect(isFrontendPath(p)).toBe(expected);
});
test('normalizes leading ./ and backslashes', () => {
expect(isFrontendPath('./styles/a.css')).toBe(true);
expect(isFrontendPath('src\\components\\A.tsx')).toBe(true);
});
});
describe.skipIf(!POSIX)('parity with bin/gstack-diff-scope', () => {
test('SCOPE_FRONTEND agrees with isFrontendPath for every sample, one file per diff', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-scope-parity-'));
const git = (...a: string[]) => {
const r = spawnSync('git', a, { cwd: dir, encoding: 'utf-8', timeout: 30_000 });
if (r.status !== 0) throw new Error(r.stderr);
};
try {
git('init', '-q', '-b', 'main');
git('config', 'user.email', 't@example.com');
git('config', 'user.name', 't');
fs.writeFileSync(path.join(dir, 'base.txt'), 'x\n');
git('add', '-A'); git('commit', '-q', '-m', 'base');
const mismatches: string[] = [];
for (const [rel, expected] of SAMPLES) {
git('checkout', '-q', '-b', 'probe');
const full = path.join(dir, rel);
fs.mkdirSync(path.dirname(full), { recursive: true });
fs.writeFileSync(full, '/* x */\n');
git('add', '-A'); git('commit', '-q', '-m', rel);
const r = spawnSync('bash', [path.join(ROOT, 'bin', 'gstack-diff-scope'), 'main'], { cwd: dir, encoding: 'utf-8', timeout: 30_000 });
const bashSays = /SCOPE_FRONTEND=true/.test(r.stdout);
if (bashSays !== expected) mismatches.push(`${rel}: bash=${bashSays} ts=${expected}`);
git('checkout', '-q', 'main'); git('branch', '-q', '-D', 'probe');
}
expect(mismatches).toEqual([]);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
});