Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
/**
* #4709 (GST-3553): a base-branch policy's local_skip names folder globs whose Playwright specs stay out of the local lane, the way a
* [] test-tree declaration does for a folder inside test/, tests/, spec/ or __tests__/. Only files pregate itself would hand to
* "playwright test" are left out: any other test under the glob still runs. Fixture code only; every runner is a shim on PATH.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { EXIT } from '../lib/headless-artifacts';
import { lanesCheck } from '../lib/pregate/checks/lanes';
import { parseConfig } from '../lib/pregate/config';
import { buildContext } from '../lib/pregate/context';
import { lanesOnlyHeadPolicy } from '../lib/pregate/head-policy';
import { BASE_PREGATE, cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
const SPEC = "import { test, expect } from '@playwright/test';\ntest('signs in', async ({ page }) => { await page.goto('/'); });\n";
const UNIT = "const test = require('node:test');\ntest('a unit test beside the specs', () => { throw new Error('unit test ran ' + 'here'); });\n";
const APP = { 'apps/web/package.json': JSON.stringify({ name: 'web', devDependencies: { '@playwright/test': '^1.48.0' } }) + '\n', 'apps/web/e2e/login.spec.ts': SPEC };
const { runner: _runner, ...NO_RUNNER } = BASE_PREGATE;
const policy = (extra: Record<string, unknown> = {}) => ({ ...NO_RUNNER, ...extra });
const LINE = /declared test tree apps\/web\/e2e\/\*\*: 1 test file\(s\) not run in the local lane \(listed in local_skip in origin\/main@[0-9a-f]{12}:\.gstack\/pregate\.json; the repo runs them in their own tier\)/;
const repos: FixtureRepo[] = [];
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
const fixture = (pregate: Record<string, unknown> | null, files: Record<string, string> = {}) => {
const repo = makeFixtureRepo({ pregate, baseFiles: { ...APP, ...files } });
repos.push(repo);
return repo;
};
/** An npx (and pnpm) first on PATH, and again through BASH_ENV, that logs its arguments and fails like a Playwright run with no server. */
const shim = (repo: FixtureRepo) => {
const dir = path.join(repo.root, 'npx-shim');
fs.mkdirSync(dir, { recursive: true });
const body = "#!/bin/sh\necho \"$@\" >> '" + path.join(dir, 'calls.log') + "'\necho 'TimeoutError: apiRequestContext.post: Timeout 30000ms exceeded.'\necho ' 1 failed'\nexit 1\n";
for (const bin of ['npx', 'pnpm']) fs.writeFileSync(path.join(dir, bin), body, { mode: 0o755 });
fs.writeFileSync(path.join(dir, 'path.sh'), "PATH='" + dir + "':\"$PATH\"\n");
return { env: { PATH: dir + ':' + (process.env.PATH ?? ''), BASH_ENV: path.join(dir, 'path.sh') }, calls: () => { try { return fs.readFileSync(path.join(dir, 'calls.log'), 'utf8'); } catch { return ''; } } };
};
const lanes = (repo: FixtureRepo, env: Record<string, string>, extra: string[] = []) => runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--only', 'lanes', '--explain', ...extra], env);
const recorded = (repo: FixtureRepo): string[] => JSON.parse(fs.readFileSync(path.join(repo.work, '.gstack', 'tmp', 'pregate.json'), 'utf8')).checks.find((c: { id: string }) => c.id === 'lanes').lines;
describe('local_skip: server-backed Playwright specs outside a test folder', () => {
// Value: protects=a green tree whose diff selects a Playwright spec under a local_skip glob passes without starting playwright;
// fails_when=the spec reaches playwright under CI=1 again (#4709); why_new=a [] only worked inside test/ tests/ spec/ __tests__/; seam=lane selection
test('a touched spec under a local_skip glob is not run, and the drop is printed and recorded', () => {
const repo = fixture(policy({ local_skip: ['apps/web/e2e/**'] }));
commit(repo, { 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const s = shim(repo);
const r = lanes(repo, s.env);
expect(s.calls()).toBe('');
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(LINE);
expect(recorded(repo).join('\n')).toMatch(LINE);
expect(r.out).toContain('no local lane; 0 requires-remote obligation(s); 1 test file(s) in declared test trees not run here');
});
test('without local_skip the same spec is routed to playwright (negative control)', () => {
const repo = fixture(policy());
commit(repo, { 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const s = shim(repo);
const r = lanes(repo, s.env);
expect(s.calls()).toContain("playwright test --reporter=list (?:^|/)e2e/login\\.spec\\.ts$");
expect(r.status).not.toBe(EXIT.ok);
expect(r.out).not.toContain('declared test tree');
});
test('a declared runner does not change what local_skip leaves out: the spec is still skipped', () => {
const repo = fixture(policy({ runner: 'node --test {files}', local_skip: ['apps/web/e2e/**'] }));
commit(repo, { 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const r = lanes(repo, shim(repo).env);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(LINE);
});
// Value: protects=a local_skip glob never skips a unit test, even an over-wide one; fails_when=local_skip drops every test under its glob
test('a unit test under a local_skip glob still runs and is named, even under an over-wide glob', () => {
for (const [glob, file] of [['apps/web/e2e/**', 'apps/web/e2e/helpers.test.js'], ['apps/web/**', 'apps/web/src/util.test.js']]) {
const repo = fixture(policy({ local_skip: [glob] }), { [file]: UNIT });
commit(repo, { [file]: UNIT + '\n' });
const r = lanes(repo, shim(repo).env);
expect(r.status).not.toBe(EXIT.ok);
expect(r.out).toContain('unit test ran here');
expect(recorded(repo).join('\n')).toContain('local_skip ' + glob + ': 1 selected test file(s) under it are not Playwright specs, so local_skip keeps them in the local lane');
}
});
// Value: protects=local_skip needs positive evidence that Playwright owns a file; fails_when=a unit test that only borrows a Playwright helper,
// or a fixture string shaped like a Playwright import, is skipped and pregate goes green without running it
test('a unit test that imports a Playwright helper, or quotes a Playwright import in a string, is not skipped', () => {
const files = {
'apps/web/e2e/borrows-expect.test.ts': "import { test } from 'vitest';\nimport { expect } from '@playwright/test';\ntest('unit', () => { expect(1).toBe(2); });\n",
'apps/web/e2e/fixture-text.spec.ts': "const FIXTURE = `\nimport { test } from '@playwright/test';\n`;\nexport default FIXTURE;\n",
};
for (const [file, text] of Object.entries(files)) {
const repo = fixture(policy({ local_skip: ['apps/web/e2e/**'] }), { [file]: text });
commit(repo, { [file]: text + '// touched\n' });
const r = lanes(repo, shim(repo).env);
expect(r.status).not.toBe(EXIT.ok);
expect(r.out).not.toContain('declared test tree');
expect(recorded(repo).join('\n')).toContain('local_skip apps/web/e2e/**: 1 selected test file(s) under it are not Playwright specs, so local_skip keeps them in the local lane');
}
});
test('an always_run spec inside the glob still runs', () => {
const repo = fixture(policy({ local_skip: ['apps/web/e2e/**'] }), { '.gstack/always-run.json': JSON.stringify({ tests: ['apps/web/e2e/**'] }) });
commit(repo, { 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const s = shim(repo);
const r = lanes(repo, s.env);
expect(s.calls()).toContain('playwright test --reporter=list');
expect(r.out).not.toContain('declared test tree');
});
test('a glob that is also a [] test tree keeps the [] wording, and a glob matching no test file is named', () => {
const repo = fixture(policy({ dependencies: { ...BASE_PREGATE.dependencies, 'tests/e2e/**': [] }, local_skip: ['tests/e2e/**', 'apps/gone/**'] }), { 'tests/e2e/home.spec.ts': SPEC, 'package.json': '{"name":"root"}\n' });
commit(repo, { 'tests/e2e/home.spec.ts': SPEC + '// touched\n' });
const r = lanes(repo, shim(repo).env);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toContain('declared test tree tests/e2e/**: 1 test file(s) not run in the local lane (declared [] in');
expect(r.out).toContain('local_skip apps/gone/** matches no test file');
});
test('on a small machine the remote gate still owes a skipped spec: the exclusion is local-only', async () => {
const repo = fixture(policy({ remote_gate: 'node scripts/remote-gate.js', local_skip: ['apps/web/e2e/**'] }));
commit(repo, { 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: true, env: { ...process.env, ...repo.env }, progress: () => {}, cores: 4, testBackend: 'local' });
if (!('ctx' in loaded)) throw new Error('fixture context refused');
const r = await lanesCheck.run(loaded.ctx);
expect(r.status).toBe('requires-remote');
expect(r.remote?.find(o => o.lane === 'pregate.json/remote_gate')?.tests).toEqual(['apps/web/e2e/login.spec.ts']);
});
});
describe('local_skip and the branch policy', () => {
test('a local_skip the branch adds is refused under --policy-from head', () => {
const repo = fixture(policy());
commit(repo, { '.gstack/pregate.json': JSON.stringify(policy({ local_skip: ['apps/web/e2e/**'] })) + '\n', 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const r = lanes(repo, shim(repo).env, ['--policy-from', 'head']);
expect(r.status).toBe(EXIT.refused);
expect(r.err).toContain('local_skip differs from the trusted policy');
expect(r.err).toContain('(PREGATE_HEAD_POLICY_LOOSENS');
});
test('with no base or user policy, a bootstrap head local_skip drops nothing', () => {
const repo = fixture(null);
commit(repo, { '.gstack/pregate.json': JSON.stringify(policy({ local_skip: ['apps/web/e2e/**'] })) + '\n', 'apps/web/e2e/login.spec.ts': SPEC + '// touched\n' });
const s = shim(repo);
const r = lanes(repo, s.env, ['--policy-from', 'head']);
expect(s.calls()).toContain('playwright test --reporter=list');
expect(r.out).not.toContain('declared test tree');
});
test('a branch that only changes local_skip gates under the base policy at /ship', () => {
const repo = fixture(policy({ local_skip: ['apps/web/e2e/**'] }));
commit(repo, { '.gstack/pregate.json': JSON.stringify(policy({ local_skip: ['apps/**'] })) + '\n' });
const v = lanesOnlyHeadPolicy(repo.work, 'main');
expect(v.head).toBe(false);
expect(v.line).toContain('also changes local_skip');
});
});
describe('local_skip in the policy schema', () => {
test('a policy holding only local_skip declares no lanes, so an unmapped file stays a warning', () => {
expect(parseConfig(JSON.stringify({ local_skip: ['apps/web/e2e/**'] })).declaresLanes).toBe(false);
const repo = fixture({ local_skip: ['apps/web/e2e/**'] });
commit(repo, { 'lib/brand-new.js': 'exports.x = 1;\n' });
const r = lanes(repo, shim(repo).env);
expect(r.out).toContain('no lane policy: lib/brand-new.js');
expect(r.out).not.toContain('FAIL lanes');
});
test('accepts folder globs and refuses everything else by path', () => {
for (const ok of [['apps/web/e2e/**'], ['apps/*/e2e/**', '**/e2e/**'], []]) expect(parseConfig(JSON.stringify({ local_skip: ok })).errors).toEqual([]);
const refused = (v: unknown) => parseConfig(JSON.stringify({ local_skip: v })).errors.map(e => [e.code, e.path]);
expect(refused('apps/web/e2e/**')).toEqual([['PREGATE_CONFIG_INVALID', 'local_skip']]);
expect(refused([1])).toEqual([['PREGATE_CONFIG_INVALID', 'local_skip']]);
for (const bad of ['**', '**/**', '*/**', 'apps/web/e2e/*.spec.ts', 'apps/web/e2e', '../x/**', '/abs/**']) expect(refused(['apps/ok/**', bad])).toEqual([['PREGATE_CONFIG_INVALID', 'local_skip[1]']]);
expect(refused(['apps/web/e2e/**', 'apps/web/e2e/**'])).toEqual([['PREGATE_CONFIG_INVALID', 'local_skip[1]']]);
expect(refused(Array.from({ length: 257 }, (_, i) => 'apps/a' + i + '/**'))).toEqual([['PREGATE_CONFIG_INVALID', 'local_skip']]);
expect(parseConfig(JSON.stringify({ local_skip: ['**'] })).errors[0]!.message).toContain('a folder glob ending in /** that names at least one literal folder');
});
});