Files
gstack/test/host-config.test.ts
T
Garry Tan 1211b6b40b community wave: 6 PRs + hardening (v0.18.1.0) (#1028)
* fix: extend tilde-in-assignment fix to design resolver + 4 skill templates

PR #993 fixed the Claude Code permission prompt for `scripts/resolvers/browse.ts`
and `gstack-upgrade/SKILL.md.tmpl`. Same bug lives in three more places that
weren't on the contributor's branch:

- `scripts/resolvers/design.ts` (3 spots: D=, B=, and _DESIGN_DIR=)
- `design-shotgun/SKILL.md.tmpl` (_DESIGN_DIR=)
- `plan-design-review/SKILL.md.tmpl` (_DESIGN_DIR=)
- `design-consultation/SKILL.md.tmpl` (_DESIGN_DIR=)
- `design-review/SKILL.md.tmpl` (REPORT_DIR=)

Replaces bare `~/` with quoted `"$HOME/..."` in the source-of-truth files, then
regenerates. `grep -rEn '^[A-Za-z_]+=~/' --include="SKILL.md" .` now returns zero
hits across all hosts (claude, codex, cursor, gbrain, hermes).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(openclaw): make native skills codex-friendly (#864)

Normalizes YAML frontmatter on the 4 hand-authored OpenClaw skills so stricter
parsers like Codex can load them. Codex CLI was rejecting these files with
"mapping values are not allowed in this context" on colons inside unquoted
description scalars.

- Drops non-standard `version` and `metadata` fields
- Rewrites descriptions into simple "Use when..." form (no inline colons)
- Adds a regression test enforcing strict frontmatter (name + description only)

Verified live: Codex CLI now loads the skills without errors. Observed during
/codex outside-voice run on the eval-community-prs plan review — Codex stderr
tripped on these exact files, which was real-world confirmation the fix is needed.

Dropped the connect-chrome changes from the original PR (the symlink removal is
out of scope for this fix; keeping connect-chrome -> open-gstack-browser).

Co-Authored-By: Cathryn Lavery <cathrynlavery@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(browse): server persists across Claude Code Bash calls

The browse server was dying between Bash tool invocations in Claude Code
because:

1. SIGTERM: The Claude Code sandbox sends SIGTERM to all child processes
   when a Bash command completes. The server received this and called
   shutdown(), deleting the state file and exiting.

2. Parent watchdog: The server polls BROWSE_PARENT_PID every 15s. When
   the parent Bash shell exits (killed by sandbox), the watchdog detected
   it and called shutdown().

Both mechanisms made it impossible to use the browse tool across multiple
Bash calls — every new `$B` invocation started a fresh server with no
cookies, no page state, and no tabs.

Fix:
- SIGTERM handler: log and ignore instead of shutdown. Explicit shutdown
  is still available via the /stop command or SIGINT (Ctrl+C).
- Parent watchdog: log once and continue instead of shutdown. The existing
  idle timeout (30 min) handles eventual cleanup.

The /stop command and SIGINT still work for intentional shutdown. Windows
behavior is unchanged (uses taskkill /F which bypasses signal handlers).

Tested: browse server survives across 5+ separate Bash tool calls in
Claude Code, maintaining cookies, page state, and navigation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(browse): gate #994 SIGTERM-ignore to normal mode only

PR #994 made browse persist across Claude Code Bash calls by ignoring SIGTERM
and parent-PID death, relying on the 30-min idle timeout for eventual cleanup.

Codex outside-voice review caught that the idle timeout doesn't apply in two
modes: headed mode (/open-gstack-browser) and tunnel mode (/pair-agent). Both
early-return from idleCheckInterval. Combined with #994's ignore-SIGTERM, those
sessions would leak forever after the user disconnects — a real resource leak on
shared machines where multiple /pair-agent sessions come and go.

Fix: gate SIGTERM-ignore and parent-PID-watchdog-ignore to normal (headless) mode
only. Headed + tunnel modes respect both signals and shutdown cleanly. Idle
timeout behavior unchanged.

Also documents the deliberate contract change for future contributors — don't
re-add global SIGTERM shutdown thinking it's missing; it's intentionally scoped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix: keep cookie picker alive after cli exits

Fixes garrytan/gstack#985

* fix: add opencode setup support

* feat(browse): add Windows browser path detection and DPAPI cookie decryption

- Extend BrowserPlatform to include win32
- Add windowsDataDir to BrowserInfo; populate for Chrome, Edge, Brave, Chromium
- getBaseDir('win32') → ~/AppData/Local
- findBrowserMatch checks Network/Cookies first on Windows (Chrome 80+)
- Add getWindowsAesKey() reading os_crypt.encrypted_key from Local State JSON
- Add dpapiDecrypt() via PowerShell ProtectedData.Unprotect (stdin/stdout)
- decryptCookieValue branches on platform: AES-256-GCM (Windows) vs AES-128-CBC (mac/linux)
- Fix hardcoded /tmp → TEMP_DIR from platform.ts in openDbFromCopy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(browse): Windows cookie import — profile discovery, v20 detection, CDP fallback

Three bugs fixed in cookie-import-browser.ts:
- listProfiles() and findInstalledBrowsers() now check Network/Cookies on Windows
  (Chrome 80+ moved cookies from profile/Cookies to profile/Network/Cookies)
- openDb() always uses copy-then-read on Windows (Chrome holds exclusive locks)
- decryptCookieValue() detects v20 App-Bound Encryption with specific error code

Added CDP-based extraction fallback (importCookiesViaCdp) for v20 cookies:
- Launches Chrome headless with --remote-debugging-port on the real profile
- Extracts cookies via Network.getAllCookies over CDP WebSocket
- Requires Chrome to be closed (v20 keys are path-bound to user-data-dir)
- Both cookie picker UI and CLI direct-import paths auto-fall back to CDP

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(browse): document CDP debug port security + log Chrome version on v20 fallback

Follow-up to #892 per Codex outside-voice review. Two small additions to the
Windows v20 App-Bound Encryption CDP fallback:

1. Inline comment documenting the deliberate security posture of the
   --remote-debugging-port. Chrome binds it to 127.0.0.1 by default, so the
   threat model is local-user-only (which is no worse than baseline — local
   attackers can already read the cookie DB). Random port 9222-9321 is for
   collision avoidance, not security. Chrome is always killed in finally.

2. One-time Chrome version log on CDP entry via /json/version. When Chrome
   inevitably changes v20 key format or /json/list shape in a future major
   version, logs will show exactly which version users are hitting.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: v0.18.1.0 — community wave (6 PRs + hardening)

VERSION bump + users-first CHANGELOG entry for the wave:
- #993 tilde-in-assignment fix (byliu-labs)
- #994 browse server persists across Bash calls (joelgreen)
- #996 cookie picker alive after cli exits (voidborne-d)
- #864 OpenClaw skills codex-friendly (cathrynlavery)
- #982 OpenCode native setup (breakneo)
- #892 Windows cookie import + DPAPI + v20 CDP fallback (msr-hickory)

Plus 3 follow-up hardening commits we own:
- Extended tilde fix to design resolver + 4 more skill templates
- Gated #994 SIGTERM-ignore to normal mode only (headed/tunnel preserve shutdown)
- Documented CDP debug port security + log Chrome version on v20 fallback

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix: review pass — package.json version, import dedup, error context, stale help

Findings from /review on the wave PR:

- [P1] package.json version was 0.18.0.1 but VERSION is 0.18.1.0, failing
  test/gen-skill-docs.test.ts:177 "package.json version matches VERSION file".
  Bumped package.json to 0.18.1.0.
- [P2] Duplicate import of cookie-picker-routes in browse/src/server.ts
  (handleCookiePickerRoute at line 20 + hasActivePicker at line 792). Merged
  into single import at top.
- [P2] cookie-import-browser.ts:494 generic rethrow loses underlying error.
  Now preserves the message so "ENOENT" vs "JSON parse error" vs "permission
  denied" are distinguishable in user output.
- [P3] setup:46 "Missing value for --host" error message listed an incomplete
  set of hosts (missing factory, openclaw, hermes, gbrain). Aligned with the
  "Unknown value" error on line 94.

Kept as-is (not real issues):
- cookie-import-browser.ts:869 empty catch on Chrome version fetch is the
  correct pattern for best-effort diagnostics (per slop-scan philosophy in
  CLAUDE.md — fire-and-forget failures shouldn't throw).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(watchdog): invert test 3 to match merged #994 behavior

main #1025 added browse/test/watchdog.test.ts with test 3 expecting the old
"watchdog kills server when parent dies" behavior. The merge with this
branch's #994 inverted that semantic — the server now STAYS ALIVE on parent
death in normal headless mode (multi-step QA across Claude Code Bash calls
depends on this).

Changes:
- Renamed test 3 from "watchdog fires when parent dies" to "server STAYS ALIVE
  when parent dies (#994)".
- Replaced 25s shutdown poll with 20s observation window asserting the server
  remains alive after the watchdog tick.
- Updated docstring to document all 3 watchdog invariants (env-var disable,
  headed-mode disable, headless persists) and note tunnel-mode coverage gap.

Verification: bun test browse/test/watchdog.test.ts → 3 pass, 0 fail (22.7s).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(ci): switch apt mirror to Hetzner to bypass Ubicloud → archive.ubuntu.com timeouts

Both build attempts of `.github/docker/Dockerfile.ci` failed at
`apt-get update` with persistent connection timeouts to archive.ubuntu.com:80
and security.ubuntu.com:80 — 90+ seconds of "connection timed out" against
every Ubuntu IP. Not a transient blip; this PR doesn't touch the Dockerfile,
and a re-run reproduced the same failure across all 9 mirror IPs.

Root cause: Ubicloud runners (Hetzner FSN1-DC21 per runner output) have
unreliable HTTP-port-80 routing to Ubuntu's official archive endpoints.

Fix:
- Rewrite /etc/apt/sources.list.d/ubuntu.sources (deb822 format in 24.04)
  to use https://mirror.hetzner.com/ubuntu/packages instead. Hetzner's
  mirror is publicly accessible from any cloud (not Hetzner-only despite
  the name) and route-local for Ubicloud's actual host. Solves both
  reliability and latency.
- Add a 3-attempt retry loop around both `apt-get update` calls as
  belt-and-suspenders. Even Hetzner's mirror can have brief blips, and the
  retry costs nothing when the first attempt succeeds.

Verification: the workflow will rebuild on push. Local `docker build` not
practical for a 12-step image with bun + claude + playwright deps + a 10-min
cold install. Trusting CI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(ci): use HTTP for Hetzner apt mirror (base image lacks ca-certificates)

Previous commit switched to https://mirror.hetzner.com/... which proved the
mirror is reachable and routes correctly (no more 90s timeouts), but exposed
a chicken-and-egg: ubuntu:24.04 ships without ca-certificates, and that's
exactly the package we're installing. Result: "No system certificates
available. Try installing ca-certificates."

Fix: use http:// for the Hetzner mirror. Apt's security model verifies
package integrity via GPG-signed Release files, not TLS, so HTTP here is
no weaker than the upstream defaults (Ubuntu's official sources also
default to HTTP for the same reason).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Cathryn Lavery <cathrynlavery@users.noreply.github.com>
Co-authored-by: Joel Green <thejoelgreen@gmail.com>
Co-authored-by: d 🔹 <258577966+voidborne-d@users.noreply.github.com>
Co-authored-by: Break <breakneo@gmail.com>
Co-authored-by: Michael Spitzer-Rubenstein <msr.ext@hickory.ai>
2026-04-17 00:45:13 -07:00

539 lines
19 KiB
TypeScript

/**
* Host config system tests — 100% coverage of host-config.ts, hosts/index.ts,
* host-config-export.ts, and golden-file regression checks.
*/
import { describe, test, expect } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
import { validateHostConfig, validateAllConfigs, type HostConfig } from '../scripts/host-config';
import {
ALL_HOST_CONFIGS,
ALL_HOST_NAMES,
HOST_CONFIG_MAP,
getHostConfig,
resolveHostArg,
getExternalHosts,
claude,
codex,
factory,
kiro,
opencode,
slate,
cursor,
openclaw,
} from '../hosts/index';
import { HOST_PATHS } from '../scripts/resolvers/types';
const ROOT = path.resolve(import.meta.dir, '..');
// ─── hosts/index.ts ─────────────────────────────────────────
describe('hosts/index.ts', () => {
test('ALL_HOST_CONFIGS has 10 hosts', () => {
expect(ALL_HOST_CONFIGS.length).toBe(10);
});
test('ALL_HOST_NAMES matches config names', () => {
expect(ALL_HOST_NAMES).toEqual(ALL_HOST_CONFIGS.map(c => c.name));
});
test('HOST_CONFIG_MAP keys match names', () => {
for (const config of ALL_HOST_CONFIGS) {
expect(HOST_CONFIG_MAP[config.name]).toBe(config);
}
});
test('individual config re-exports match registry', () => {
expect(claude.name).toBe('claude');
expect(codex.name).toBe('codex');
expect(factory.name).toBe('factory');
expect(kiro.name).toBe('kiro');
expect(opencode.name).toBe('opencode');
expect(slate.name).toBe('slate');
expect(cursor.name).toBe('cursor');
expect(openclaw.name).toBe('openclaw');
});
test('getHostConfig returns correct config', () => {
const c = getHostConfig('codex');
expect(c.name).toBe('codex');
expect(c.displayName).toBe('OpenAI Codex CLI');
});
test('getHostConfig throws on unknown host', () => {
expect(() => getHostConfig('nonexistent')).toThrow('Unknown host');
});
test('resolveHostArg resolves direct names', () => {
for (const name of ALL_HOST_NAMES) {
expect(resolveHostArg(name)).toBe(name);
}
});
test('resolveHostArg resolves aliases', () => {
expect(resolveHostArg('agents')).toBe('codex');
expect(resolveHostArg('droid')).toBe('factory');
});
test('resolveHostArg throws on unknown alias', () => {
expect(() => resolveHostArg('nonexistent')).toThrow('Unknown host');
});
test('getExternalHosts excludes claude', () => {
const external = getExternalHosts();
expect(external.find(c => c.name === 'claude')).toBeUndefined();
expect(external.length).toBe(ALL_HOST_CONFIGS.length - 1);
});
test('every host has a unique name', () => {
const names = new Set(ALL_HOST_NAMES);
expect(names.size).toBe(ALL_HOST_NAMES.length);
});
test('every host has a unique hostSubdir', () => {
const subdirs = new Set(ALL_HOST_CONFIGS.map(c => c.hostSubdir));
expect(subdirs.size).toBe(ALL_HOST_CONFIGS.length);
});
test('every host has a unique globalRoot', () => {
const roots = new Set(ALL_HOST_CONFIGS.map(c => c.globalRoot));
expect(roots.size).toBe(ALL_HOST_CONFIGS.length);
});
});
// ─── validateHostConfig ─────────────────────────────────────
describe('validateHostConfig', () => {
function makeValid(): HostConfig {
return {
name: 'test-host',
displayName: 'Test Host',
cliCommand: 'testcli',
globalRoot: '.test/skills/gstack',
localSkillRoot: '.test/skills/gstack',
hostSubdir: '.test',
usesEnvVars: true,
frontmatter: { mode: 'allowlist', keepFields: ['name', 'description'] },
generation: { generateMetadata: false },
pathRewrites: [],
runtimeRoot: { globalSymlinks: ['bin'] },
install: { prefixable: false, linkingStrategy: 'symlink-generated' },
};
}
test('valid config passes', () => {
expect(validateHostConfig(makeValid())).toEqual([]);
});
test('invalid name is caught', () => {
const c = makeValid();
c.name = 'UPPER_CASE';
const errors = validateHostConfig(c);
expect(errors.some(e => e.includes('name'))).toBe(true);
});
test('name with special chars is caught', () => {
const c = makeValid();
c.name = 'has spaces';
expect(validateHostConfig(c).length).toBeGreaterThan(0);
});
test('empty displayName is caught', () => {
const c = makeValid();
c.displayName = '';
expect(validateHostConfig(c).some(e => e.includes('displayName'))).toBe(true);
});
test('invalid cliCommand is caught', () => {
const c = makeValid();
c.cliCommand = 'has spaces';
expect(validateHostConfig(c).some(e => e.includes('cliCommand'))).toBe(true);
});
test('invalid cliAlias is caught', () => {
const c = makeValid();
c.cliAliases = ['good', 'BAD!'];
expect(validateHostConfig(c).some(e => e.includes('cliAlias'))).toBe(true);
});
test('valid cliAliases pass', () => {
const c = makeValid();
c.cliAliases = ['alias-one', 'alias-two'];
expect(validateHostConfig(c)).toEqual([]);
});
test('invalid globalRoot is caught', () => {
const c = makeValid();
c.globalRoot = 'path with spaces';
expect(validateHostConfig(c).some(e => e.includes('globalRoot'))).toBe(true);
});
test('invalid localSkillRoot is caught', () => {
const c = makeValid();
c.localSkillRoot = 'invalid<path>';
expect(validateHostConfig(c).some(e => e.includes('localSkillRoot'))).toBe(true);
});
test('invalid hostSubdir is caught', () => {
const c = makeValid();
c.hostSubdir = 'no spaces allowed';
expect(validateHostConfig(c).some(e => e.includes('hostSubdir'))).toBe(true);
});
test('invalid frontmatter.mode is caught', () => {
const c = makeValid();
(c.frontmatter as any).mode = 'invalid';
expect(validateHostConfig(c).some(e => e.includes('frontmatter.mode'))).toBe(true);
});
test('invalid linkingStrategy is caught', () => {
const c = makeValid();
(c.install as any).linkingStrategy = 'invalid';
expect(validateHostConfig(c).some(e => e.includes('linkingStrategy'))).toBe(true);
});
test('paths with $ and ~ are valid', () => {
const c = makeValid();
c.globalRoot = '$HOME/.test/skills/gstack';
c.localSkillRoot = '~/.test/skills/gstack';
expect(validateHostConfig(c)).toEqual([]);
});
test('shell injection attempt in cliCommand is caught', () => {
const c = makeValid();
c.cliCommand = 'opencode;rm -rf /';
expect(validateHostConfig(c).some(e => e.includes('cliCommand'))).toBe(true);
});
});
// ─── validateAllConfigs ─────────────────────────────────────
describe('validateAllConfigs', () => {
test('real configs all pass validation', () => {
const errors = validateAllConfigs(ALL_HOST_CONFIGS);
expect(errors).toEqual([]);
});
test('duplicate name detected', () => {
const dup = { ...codex, name: 'claude' } as HostConfig;
const errors = validateAllConfigs([claude, dup]);
expect(errors.some(e => e.includes('Duplicate name'))).toBe(true);
});
test('duplicate hostSubdir detected', () => {
const dup = { ...codex, name: 'dup-host', hostSubdir: '.claude', globalRoot: '.dup/skills/gstack' } as HostConfig;
const errors = validateAllConfigs([claude, dup]);
expect(errors.some(e => e.includes('Duplicate hostSubdir'))).toBe(true);
});
test('duplicate globalRoot detected', () => {
const dup = { ...codex, name: 'dup-host', hostSubdir: '.dup', globalRoot: '.claude/skills/gstack' } as HostConfig;
const errors = validateAllConfigs([claude, dup]);
expect(errors.some(e => e.includes('Duplicate globalRoot'))).toBe(true);
});
test('per-config validation errors are prefixed with host name', () => {
const bad = { ...codex, name: 'BAD', cliCommand: 'also bad' } as HostConfig;
const errors = validateAllConfigs([bad]);
expect(errors.every(e => e.startsWith('[BAD]'))).toBe(true);
});
});
// ─── HOST_PATHS derivation ──────────────────────────────────
describe('HOST_PATHS derivation from configs', () => {
test('Claude uses literal home paths (no env vars)', () => {
expect(HOST_PATHS.claude.skillRoot).toBe('~/.claude/skills/gstack');
expect(HOST_PATHS.claude.binDir).toBe('~/.claude/skills/gstack/bin');
expect(HOST_PATHS.claude.browseDir).toBe('~/.claude/skills/gstack/browse/dist');
expect(HOST_PATHS.claude.designDir).toBe('~/.claude/skills/gstack/design/dist');
});
test('Codex uses $GSTACK_ROOT env vars', () => {
expect(HOST_PATHS.codex.skillRoot).toBe('$GSTACK_ROOT');
expect(HOST_PATHS.codex.binDir).toBe('$GSTACK_BIN');
expect(HOST_PATHS.codex.browseDir).toBe('$GSTACK_BROWSE');
expect(HOST_PATHS.codex.designDir).toBe('$GSTACK_DESIGN');
});
test('every host with usesEnvVars=true gets env var paths', () => {
for (const config of ALL_HOST_CONFIGS) {
if (config.usesEnvVars) {
expect(HOST_PATHS[config.name].skillRoot).toBe('$GSTACK_ROOT');
expect(HOST_PATHS[config.name].binDir).toBe('$GSTACK_BIN');
}
}
});
test('every host with usesEnvVars=false gets literal paths', () => {
for (const config of ALL_HOST_CONFIGS) {
if (!config.usesEnvVars) {
expect(HOST_PATHS[config.name].skillRoot).toContain('~/');
expect(HOST_PATHS[config.name].binDir).toContain('/bin');
}
}
});
test('localSkillRoot matches config for every host', () => {
for (const config of ALL_HOST_CONFIGS) {
expect(HOST_PATHS[config.name].localSkillRoot).toBe(config.localSkillRoot);
}
});
test('HOST_PATHS has entry for every registered host', () => {
for (const name of ALL_HOST_NAMES) {
expect(HOST_PATHS[name]).toBeDefined();
}
});
});
// ─── host-config-export.ts CLI ──────────────────────────────
describe('host-config-export.ts CLI', () => {
const EXPORT_SCRIPT = path.join(ROOT, 'scripts', 'host-config-export.ts');
function run(...args: string[]): { stdout: string; stderr: string; exitCode: number } {
const result = Bun.spawnSync(['bun', 'run', EXPORT_SCRIPT, ...args], {
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
});
return {
stdout: result.stdout.toString().trim(),
stderr: result.stderr.toString().trim(),
exitCode: result.exitCode,
};
}
test('list prints all host names', () => {
const { stdout, exitCode } = run('list');
expect(exitCode).toBe(0);
const names = stdout.split('\n');
expect(names).toEqual(ALL_HOST_NAMES);
});
test('get returns string field', () => {
const { stdout, exitCode } = run('get', 'codex', 'globalRoot');
expect(exitCode).toBe(0);
expect(stdout).toBe('.codex/skills/gstack');
});
test('get returns boolean as 1/0', () => {
const { stdout: t } = run('get', 'claude', 'usesEnvVars');
expect(t).toBe('0');
const { stdout: f } = run('get', 'codex', 'usesEnvVars');
expect(f).toBe('1');
});
test('get with missing args exits 1', () => {
const { exitCode } = run('get', 'codex');
expect(exitCode).toBe(1);
});
test('get with unknown field exits 1', () => {
const { exitCode } = run('get', 'codex', 'nonexistent');
expect(exitCode).toBe(1);
});
test('get with unknown host exits 1', () => {
const { exitCode } = run('get', 'nonexistent', 'name');
expect(exitCode).not.toBe(0);
});
test('validate passes for real configs', () => {
const { stdout, exitCode } = run('validate');
expect(exitCode).toBe(0);
expect(stdout).toContain('configs valid');
});
test('symlinks returns asset list', () => {
const { stdout, exitCode } = run('symlinks', 'codex');
expect(exitCode).toBe(0);
const lines = stdout.split('\n');
expect(lines).toContain('bin');
expect(lines).toContain('ETHOS.md');
expect(lines).toContain('review/checklist.md');
});
test('opencode symlinks returns nested runtime assets', () => {
const { stdout, exitCode } = run('symlinks', 'opencode');
expect(exitCode).toBe(0);
const lines = stdout.split('\n');
expect(lines).toContain('bin');
expect(lines).toContain('browse/dist');
expect(lines).toContain('browse/bin');
expect(lines).toContain('review/design-checklist.md');
expect(lines).toContain('review/greptile-triage.md');
expect(lines).toContain('review/specialists');
expect(lines).toContain('qa/templates');
expect(lines).toContain('qa/references');
expect(lines).toContain('plan-devex-review/dx-hall-of-fame.md');
});
test('symlinks with missing host exits 1', () => {
const { exitCode } = run('symlinks');
expect(exitCode).toBe(1);
});
test('detect finds claude (since we are running in claude)', () => {
const { stdout, exitCode } = run('detect');
expect(exitCode).toBe(0);
// claude binary should be on PATH in this environment
expect(stdout).toContain('claude');
});
test('unknown command exits 1', () => {
const { exitCode } = run('badcommand');
expect(exitCode).toBe(1);
});
});
// ─── Golden-file regression ─────────────────────────────────
describe('golden-file regression', () => {
const GOLDEN_DIR = path.join(ROOT, 'test', 'fixtures', 'golden');
test('Claude ship skill matches golden baseline', () => {
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'claude-ship-SKILL.md'), 'utf-8');
const current = fs.readFileSync(path.join(ROOT, 'ship', 'SKILL.md'), 'utf-8');
expect(current).toBe(golden);
});
test('Codex ship skill matches golden baseline', () => {
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'codex-ship-SKILL.md'), 'utf-8');
const current = fs.readFileSync(path.join(ROOT, '.agents', 'skills', 'gstack-ship', 'SKILL.md'), 'utf-8');
expect(current).toBe(golden);
});
test('Factory ship skill matches golden baseline', () => {
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'factory-ship-SKILL.md'), 'utf-8');
const current = fs.readFileSync(path.join(ROOT, '.factory', 'skills', 'gstack-ship', 'SKILL.md'), 'utf-8');
expect(current).toBe(golden);
});
});
// ─── Individual host config correctness ─────────────────────
describe('host config correctness', () => {
test('claude is the only prefixable host', () => {
for (const config of ALL_HOST_CONFIGS) {
if (config.name === 'claude') {
expect(config.install.prefixable).toBe(true);
} else {
expect(config.install.prefixable).toBe(false);
}
}
});
test('claude is the only host with real-dir-symlink strategy', () => {
for (const config of ALL_HOST_CONFIGS) {
if (config.name === 'claude') {
expect(config.install.linkingStrategy).toBe('real-dir-symlink');
} else {
expect(config.install.linkingStrategy).toBe('symlink-generated');
}
}
});
test('claude does not use env vars', () => {
expect(claude.usesEnvVars).toBe(false);
});
test('all external hosts use env vars', () => {
for (const config of getExternalHosts()) {
expect(config.usesEnvVars).toBe(true);
}
});
test('codex has 1024-char description limit with error behavior', () => {
expect(codex.frontmatter.descriptionLimit).toBe(1024);
expect(codex.frontmatter.descriptionLimitBehavior).toBe('error');
});
test('codex generates openai.yaml metadata', () => {
expect(codex.generation.generateMetadata).toBe(true);
expect(codex.generation.metadataFormat).toBe('openai.yaml');
});
test('codex has sidecar config', () => {
expect(codex.sidecar).toBeDefined();
expect(codex.sidecar!.path).toBe('.agents/skills/gstack');
});
test('factory has tool rewrites', () => {
expect(factory.toolRewrites).toBeDefined();
expect(Object.keys(factory.toolRewrites!).length).toBeGreaterThan(0);
expect(factory.toolRewrites!['use the Bash tool']).toBe('run this command');
});
test('factory has conditional disable-model-invocation field', () => {
expect(factory.frontmatter.conditionalFields).toBeDefined();
expect(factory.frontmatter.conditionalFields!.length).toBe(1);
expect(factory.frontmatter.conditionalFields![0].if).toEqual({ sensitive: true });
expect(factory.frontmatter.conditionalFields![0].add).toEqual({ 'disable-model-invocation': true });
});
test('codex has suppressedResolvers for self-invocation prevention', () => {
expect(codex.suppressedResolvers).toBeDefined();
expect(codex.suppressedResolvers).toContain('CODEX_SECOND_OPINION');
expect(codex.suppressedResolvers).toContain('ADVERSARIAL_STEP');
expect(codex.suppressedResolvers).toContain('REVIEW_ARMY');
});
test('codex has boundary instruction', () => {
expect(codex.boundaryInstruction).toBeDefined();
expect(codex.boundaryInstruction).toContain('Do NOT read');
});
test('openclaw has tool rewrites for exec/read/write', () => {
expect(openclaw.toolRewrites).toBeDefined();
expect(openclaw.toolRewrites!['use the Bash tool']).toBe('use the exec tool');
expect(openclaw.toolRewrites!['use the Read tool']).toBe('use the read tool');
});
test('openclaw has CLAUDE.md→AGENTS.md path rewrite', () => {
expect(openclaw.pathRewrites.some(r => r.from === 'CLAUDE.md' && r.to === 'AGENTS.md')).toBe(true);
});
test('openclaw has no adapter (dead code removed)', () => {
expect(openclaw.adapter).toBeUndefined();
});
test('openclaw has no staticFiles (SOUL.md removed)', () => {
expect(openclaw.staticFiles).toBeUndefined();
});
test('openclaw includeSkills is empty (native skills replaced generated ones)', () => {
expect(openclaw.generation.includeSkills).toBeDefined();
expect(openclaw.generation.includeSkills!.length).toBe(0);
});
test('every host has coAuthorTrailer or undefined', () => {
// Claude, Codex, Factory, OpenClaw have explicit trailers
expect(claude.coAuthorTrailer).toContain('Claude');
expect(codex.coAuthorTrailer).toContain('Codex');
expect(factory.coAuthorTrailer).toContain('Factory');
expect(openclaw.coAuthorTrailer).toContain('OpenClaw');
});
test('every external host skips the codex skill', () => {
for (const config of getExternalHosts()) {
expect(config.generation.skipSkills).toContain('codex');
}
});
test('every host has at least one pathRewrite (except claude)', () => {
for (const config of getExternalHosts()) {
expect(config.pathRewrites.length).toBeGreaterThan(0);
}
expect(claude.pathRewrites.length).toBe(0);
});
test('every host has runtimeRoot.globalSymlinks', () => {
for (const config of ALL_HOST_CONFIGS) {
expect(config.runtimeRoot.globalSymlinks.length).toBeGreaterThan(0);
expect(config.runtimeRoot.globalSymlinks).toContain('bin');
expect(config.runtimeRoot.globalSymlinks).toContain('ETHOS.md');
}
});
});