mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-09 14:38:59 +02:00
bin/gstack-design-detect.ts finds and runs an impeccable engine the user installed; it never installs, downloads, or executes anything that could download. `probe` reads only: config (design_detector off → DISABLED), IMPECCABLE_BIN (absolute, realpath outside the repo and cwd), a PATH walk (absolute entries outside the repo; a #! shim counts as launcher-present, never READY), the ~/.impeccable/bin/<newest semver>/ cache, and the engine installed beside a skill launcher (scripts/bin/<os>-<arch>/impeccable, the layout a real install produced). It reports IMPECCABLE_SKILL, host-aware IMPECCABLE_HOOK (+ HOOK_OTHER), the ignore lists from .impeccable/config*.json, IMPECCABLE_ENGINE_UNTESTED for versions outside the fixture set, and a hint only when a launcher exists without its engine. `scan` re-probes, refuses URLs and anything outside the repo root or the design-report allow-list (realpath, so symlinks cannot escape), derives `--changed <base>` targets NUL-safely through git and lib/frontend-scope.ts, batches 100 absolute paths per engine call with stdin ignored, a SIGKILL timeout, a 50 MB stdout cap, and sanitized length-capped fields, then prints one normalized JSON document (--format gstack) or the engine's bytes (--format raw); DETECT_TOP (fenced as untrusted content), DETECT_SUMMARY, and DETECT_EXIT go to stderr; exit code passes through with 1 over 2 over 0; exit 3 is a gstack bug. `rules` prints the mapped set. Every run appends a content-free line to the local analytics file. lib/design-detect-contract.ts owns every sentinel string, the limits, and the normalized-finding shape (pure module); test/design-detect-contract.test.ts asserts every sentinel-shaped token the agent can read exists there. lib/frontend-scope.ts mirrors gstack-diff-scope's frontend arm, pinned by a parity test that runs the bash script. bin/gstack-config gains design_detector (auto | off, default auto, invalid values rejected with the file unchanged). test/fixtures/fake-impeccable.ts is the env-driven engine stand-in; test/gstack-design-detect.test.ts covers READY/NOT_CACHED/ NOT_AVAILABLE/DISABLED, env trust (.env never loaded, in-repo IMPECCABLE_BIN ignored), newest-semver cache, hook and ignore detection, refusals, exit passthrough, raw byte-identity, normalization, the display cap, timeout, parse errors, diagnostics, --changed, and analytics. The egress scanner test records the wrapper as a documented non-sink. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
87 lines
3.2 KiB
TypeScript
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' });
|
|
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' });
|
|
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 });
|
|
}
|
|
});
|
|
});
|