mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 22:14:25 +01:00
* Fix spaced-out terminal text on Windows: put a Latin monospace before the CJK fallbacks On Windows none of the Mac/Linux monospace fonts in the stack are installed, so the first font that resolves is Malgun Gothic (the Windows Korean UI font). xterm.js sizes its character cell from that font's advance width, and Malgun Gothic advances Latin glyphs in a full-width CJK cell — doubling every cell and rendering the whole terminal (and the sidepanel mono UI) as spaced-out text. Insert Consolas (present on every Windows install) and the Cascadia faces ahead of the CJK fonts in both the xterm fontFamily and the --font-mono CSS var. The CJK fonts stay last for actual CJK coverage. No bundled font, no user install needed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GKj8Nr8T4GvryTcWBJRMyC * fix(windows): every compiled binary answers --version before any side effect browse --version started a server and exited 1, pdf printed usage and exited 1, gstack-global-discover rejected the flag, and find-browse ran discovery. A launch probe for Smart App Control (#2595) needs one side-effect-free command that exits 0 on a healthy build, so browse, find-browse, make-pdf and gstack-global-discover now answer --version first (design already did). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(extension): pin Consolas ahead of the CJK fallbacks in both mono stacks (#2287) Regression test for @tomfluff's fix: the xterm fontFamily and --font-mono must list Consolas before Noto Sans Mono CJK KR and Malgun Gothic, or Windows renders the sidebar terminal double-width. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(cso): record each CSO build's outcome and stop arming the parent trap across the native publisher exec (#3071) scripts/build-cso.sh now writes bin/.gstack-cso-build-result: result, failed stage (build or publish), reason, this revision, the revision of the generation still installed, whether its launcher is usable, and the diagnostic log. An 'interrupted' entry is written before each stage so a killed run is visible. A failed publish that restores the old generation records it as still installed. Before exec'ing the native publisher, the parent re-checks the locker, clears its EXIT trap and enables execfail: the locked child's own trap owns the stage. On Git Bash an exec of a native program may not replace the shell, so the parent's trap could otherwise delete the stage under the running child (the vanishing files in #3071; root cause unproven). If the exec itself fails the parent cleans the stage and records it. The Windows build prefers PowerShell 7 (pwsh) over Windows PowerShell 5.1, which crashed outright on the reporter's machine. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(setup): an optional CSO build or publish failure no longer aborts setup (#3071) CSO was optional at probe time but fatal at build time: scripts/build.sh ran build-cso.sh under set -e before the browse server bundle and the completion stamp, and setup exited when the CSO artifact set was incomplete. A failed CSO step now prints 'CSO unavailable: the <stage> step failed' with its log (bin/.gstack-cso-build.log) and retry, and the build and setup finish. GSTACK_STRICT_BUILD=1 keeps it fatal; the free-tests, make-pdf-gate and windows-setup-e2e builds set it, so regressions still fail CI. setup's summary reads the build-result record instead of the pre-build availability flag: probe failures keep their prerequisite instruction; build and publish failures name the stage, the diagnostic and 'bun run build:cso && ./setup', and a restored earlier helper is reported as 'previous CSO kept: <revision>'. setup records probe failures in the same file. The Windows prerequisite probe prefers pwsh, and a probe that fails for any reason other than a missing toolchain or a compile error keeps its exit status and first output line (windows-toolchain-probe) instead of being labeled windows-msvc-toolchain. Reported and diagnosed by @dviolante. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * feat(windows): detect Smart App Control-blocked binaries in setup and gstack-doctor (#2595, #2124) Smart App Control refuses the five unsigned binaries gstack compiles locally, and Git Bash reports it as 'Permission denied', so setup's [ -x ] gate passed and skills failed later. bin/gstack-launch-probe.sh runs each binary's side-effect-free --version and classifies it: native, blocked (spawn error, exit 126/127, or an application-control message), broken (launched, exited non-zero) or missing. It shows the raw first output line, since the exact Windows text is unverified. On Windows, setup names each blocked binary and the skills that need it, cites #2595, says which shell ran setup and whether WSL is installed, gives today's workarounds (WSL, or turning Smart App Control off), how to undo, and the new troubleshooting section. gstack-doctor's browse row now says 'blocked at launch' instead of passing, a binaries row covers the other four, and a cso row reads the build-result record. windows-setup-e2e builds with GSTACK_STRICT_BUILD=1, checks all five binaries answer --version, and adds two forced CSO failures: fatal under strict mode, and a completed setup that reports the failure and a doctor cso warning under GSTACK_STRICT_BUILD=0. No shim or launcher: it could not be called from PowerShell and would load the caller's project .env/bunfig. Signing is the follow-up in TODOS.md. Diagnosis credit: @knetics9000 (#2595, #2596), @smartjelic-sys (#2595), @pstilwell90 (#2124), @cko32002 (#2265), @salluexez (#2127). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: Windows Smart App Control known issue, optional CSO failures, doctor rows README's Windows section says /cso failures no longer stop setup (GSTACK_STRICT_BUILD=1 keeps them fatal), documents Smart App Control as a known issue with today's workarounds (WSL, or turning it off) and the Consolas fix. troubleshooting.md gains a Windows section for blocked binaries and an entry for CSO build/publish failures. TODOS.md replaces the Node CLI lane item with Windows code signing (needs a signing account), the #3071 root-cause follow-up and SAC text verification. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(setup): never write the CSO build record into a source checkout that needed no build Setup wrote bin/.gstack-cso-build-result for every probe-stage outcome, so a run that built nothing still changed the source checkout's bin/ (caught by setup-codex-scope's unchanged-source checks). A missing prerequisite now comes from the run's own probe, as before, and setup only removes a stale record alongside the removed helper. scripts/build-cso.sh remains the only writer. The doctor's cso row reports 'native helper not built' with no record. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(extension): move the Consolas font-stack check into sidebar-ux (#2287) The standalone file read extension sources without importing product code, which the test-of-test ratchet rejects; sidebar-ux already owns the sidepanel.css structural checks. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * v1.91.43.0 fix(windows): setup degrades instead of dying on a CSO failure, detects Smart App Control, Consolas terminal font Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Yotam <yotsurfing@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
148 lines
8.4 KiB
TypeScript
148 lines
8.4 KiB
TypeScript
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
import { runBashScript } from './helpers/bash-script';
|
|
|
|
// #3071: an optional CSO failure no longer aborts setup. The prerequisite
|
|
// probe prefers PowerShell 7 and keeps an unknown failure's own output; the
|
|
// summary reads bin/.gstack-cso-build-result and names the failed stage, the
|
|
// diagnostic and the retry; only GSTACK_STRICT_BUILD=1 makes an incomplete CSO
|
|
// set fatal. Runs setup's real blocks with tools stubbed.
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
const setup = fs.readFileSync(path.join(ROOT, 'setup'), 'utf8');
|
|
const fn = (name: string) => {
|
|
const start = setup.indexOf(`\n${name}() {`);
|
|
const end = setup.indexOf('\n}\n', start);
|
|
if (start < 0 || end < 0) throw new Error(`missing setup function ${name}`);
|
|
return setup.slice(start + 1, end + 3);
|
|
};
|
|
const between = (from: string, to: string) => {
|
|
const start = setup.indexOf(from);
|
|
const end = setup.indexOf(to, start);
|
|
if (start < 0 || end < 0) throw new Error(`missing setup block ${from}`);
|
|
return setup.slice(start, end);
|
|
};
|
|
const SUMMARY_END = '#cso-build-or-publish-failed"\nfi\n';
|
|
const SUMMARY = between('# ─── CSO native-helper summary', SUMMARY_END) + SUMMARY_END;
|
|
const GATE = between('_CSO_READY=0\n', 'if [ "$_CSO_READY" -eq 1 ]; then');
|
|
const tmps: string[] = [];
|
|
afterEach(() => { for (const t of tmps.splice(0)) fs.rmSync(t, { recursive: true, force: true }); });
|
|
const temp = (prefix: string) => { const d = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); tmps.push(d); return d; };
|
|
const stub = (dir: string, name: string, body: string) => fs.writeFileSync(path.join(dir, name), `#!/bin/sh\n${body}\n`, { mode: 0o755 });
|
|
|
|
function probe(tools: Record<string, string>) {
|
|
const dir = temp('gstack-cso-probe-');
|
|
for (const [name, body] of Object.entries(tools)) stub(dir, name, body);
|
|
stub(dir, 'cygpath', 'shift; echo "$1"');
|
|
return runBashScript([
|
|
'IS_WINDOWS=1', `SOURCE_GSTACK_DIR="${ROOT}"`,
|
|
'bun_cmd() { echo "--no-compile-autoload-dotenv --no-compile-autoload-bunfig --no-compile-autoload-tsconfig --no-compile-autoload-package-json"; }',
|
|
fn('_cso_unavailable'), fn('probe_cso_build_prerequisites'),
|
|
'probe_cso_build_prerequisites',
|
|
'printf "available=%s\\nreason=%s\\ndetail=%s\\n" "$CSO_BUILD_AVAILABLE" "$CSO_FAIL_REASON" "$CSO_PROBE_DETAIL"',
|
|
].join('\n'), { env: { ...process.env, PATH: `${dir}:${process.env.PATH}` }, timeout: 30_000 });
|
|
}
|
|
|
|
function summary(record: string | null, opts: { launcher?: boolean; probe?: [reason: string, detail: string] } = {}) {
|
|
const dir = temp('gstack-cso-summary-');
|
|
fs.mkdirSync(path.join(dir, 'bin'));
|
|
if (record !== null) fs.writeFileSync(path.join(dir, 'bin/.gstack-cso-build-result'), record);
|
|
if (opts.launcher) for (const name of ['gstack-cso-launcher', 'gstack-cso-core']) stub(path.join(dir, 'bin'), name, 'echo OLD');
|
|
const probe = opts.probe ? `CSO_BUILD_AVAILABLE=0\nCSO_FAIL_REASON='${opts.probe[0]}'\nCSO_PROBE_DETAIL='${opts.probe[1]}'` : 'CSO_BUILD_AVAILABLE=1';
|
|
const r = runBashScript(['QUIET=0', '_EXE=""', `SOURCE_GSTACK_DIR="${dir}"`, probe, 'log() { echo "$@"; }', SUMMARY].join('\n'), { timeout: 15_000 });
|
|
expect(r.status).toBe(0);
|
|
return { out: r.stdout, dir };
|
|
}
|
|
|
|
describe.skipIf(process.platform === 'win32')('setup: Windows CSO probe uses PowerShell 7 and keeps unknown failures (#3071)', () => {
|
|
test('pwsh is preferred over Windows PowerShell 5.1', () => {
|
|
const r = probe({ pwsh: 'exit 0', 'powershell.exe': 'echo "5.1 must not run" >&2; exit 1' });
|
|
expect(r.stdout).toContain('available=1\n');
|
|
});
|
|
|
|
test('a crashed probe keeps its exit status and output instead of blaming the MSVC toolchain', () => {
|
|
const r = probe({ pwsh: 'echo "Fatal error. 0xC0000005"; exit 139' });
|
|
expect(r.stdout).toContain('reason=windows-toolchain-probe\n');
|
|
expect(r.stdout).toContain('detail=pwsh exited 139: Fatal error. 0xC0000005\n');
|
|
});
|
|
|
|
test('the missing Visual Studio message still maps to the install instruction', () => {
|
|
const r = probe({ pwsh: "echo 'CSO Windows build requires Visual Studio 2022 Build Tools with the Desktop development with C++ workload.' >&2; exit 1" });
|
|
expect(r.stdout).toContain('reason=windows-msvc-toolchain\n');
|
|
});
|
|
|
|
test.skipIf(Bun.which('pwsh') !== null)('without pwsh the probe falls back to powershell.exe', () => {
|
|
const r = probe({ 'powershell.exe': 'echo "Native CSO Windows compiler probe failed (2)." >&2; exit 1' });
|
|
expect(r.stdout).toContain('reason=windows-msvc-compile\n');
|
|
});
|
|
});
|
|
|
|
describe.skipIf(process.platform === 'win32')('setup: CSO summary reads the build-result record per stage (#3071)', () => {
|
|
const failed = (stage: string, reason: string, installed = '') =>
|
|
`result=failed\nstage=${stage}\nreason=${reason}\nrevision=1.91.99.0 (abcdef123456)\ninstalled=${installed}\nlauncher=${installed ? 'yes' : 'no'}\ndiagnostic=/src/bin/.gstack-cso-build.log\n`;
|
|
|
|
test('a probe failure keeps the prerequisite instruction and names the probe stage', () => {
|
|
const { out } = summary(null, { probe: ['windows-toolchain-probe', 'pwsh exited 139: Fatal error'] });
|
|
expect(out).toContain('CSO unavailable: its native helper was not built (windows-toolchain-probe).');
|
|
expect(out).toContain('Failed stage: probe.');
|
|
expect(out).toContain('fix the PowerShell toolchain probe failure (pwsh exited 139: Fatal error)');
|
|
});
|
|
|
|
test('a fresh build failure names the stage, the log and the retry, never a prerequisite install', () => {
|
|
const { out, dir } = summary(failed('build', 'exit 42'));
|
|
expect(out).toContain("CSO unavailable: the native helper's build step failed (exit 42), so /cso will report not assessed.");
|
|
expect(out).toContain('Diagnostic: /src/bin/.gstack-cso-build.log');
|
|
expect(out).toContain('Everything else is installed and works.');
|
|
expect(out).toContain(`Retry: cd ${dir} && bun run build:cso && ./setup`);
|
|
expect(out).toContain('troubleshooting.md#cso-build-or-publish-failed');
|
|
expect(out).not.toContain('To enable /cso');
|
|
expect(out).not.toMatch(/prerequisite|\binstall (?:a|the|Visual|Git|Bun)\b/i);
|
|
});
|
|
|
|
test('a failed publish that kept the earlier helper says previous CSO kept', () => {
|
|
const { out } = summary(failed('publish', 'exit 1', '1.91.34.0 (f67c478f05d8)'), { launcher: true });
|
|
expect(out).toContain('CSO publish step failed (exit 1) for 1.91.99.0 (abcdef123456); previous CSO kept: 1.91.34.0 (f67c478f05d8).');
|
|
expect(out).not.toContain('CSO unavailable');
|
|
});
|
|
|
|
test('a recorded old helper whose files are gone is reported unavailable', () => {
|
|
expect(summary(failed('publish', 'exit 1', '1.91.34.0'), { launcher: false }).out).toContain("CSO unavailable: the native helper's publish step failed (exit 1)");
|
|
});
|
|
|
|
test('an interrupted publish says so', () => {
|
|
expect(summary(failed('publish', 'interrupted')).out).toContain("publish step was interrupted");
|
|
});
|
|
|
|
test('a successful build or a legacy install without a record prints nothing', () => {
|
|
expect(summary('result=ok\nstage=publish\nreason=committed\nrevision=1\ninstalled=1\nlauncher=yes\ndiagnostic=x\n').out).toBe('');
|
|
expect(summary(null).out).toBe('');
|
|
});
|
|
});
|
|
|
|
test('a probe failure removes a stale build record and writes nothing into the source checkout', () => {
|
|
const block = between('if [ "$CSO_BUILD_AVAILABLE" -eq 0 ]; then\n rm -f', '\nfi\n');
|
|
expect(block).toContain('rm -f "$SOURCE_GSTACK_DIR/bin/.gstack-cso-build-result"');
|
|
expect(block).not.toContain('>');
|
|
});
|
|
|
|
describe.skipIf(process.platform === 'win32')('setup: an incomplete CSO set is fatal only under GSTACK_STRICT_BUILD=1 (#3071)', () => {
|
|
function gate(strict?: string) {
|
|
const dir = temp('gstack-cso-gate-');
|
|
fs.mkdirSync(path.join(dir, 'bin'));
|
|
const env: Record<string, string> = { PATH: process.env.PATH ?? '' };
|
|
if (strict !== undefined) env.GSTACK_STRICT_BUILD = strict;
|
|
return runBashScript(['set -e', 'CSO_BUILD_AVAILABLE=1', 'IS_WINDOWS=0', '_EXE=""', `SOURCE_GSTACK_DIR="${dir}"`, GATE, 'echo "ready=$_CSO_READY"'].join('\n'), { env, timeout: 15_000 });
|
|
}
|
|
test('by default setup continues without CSO', () => {
|
|
const r = gate();
|
|
expect(r.status).toBe(0);
|
|
expect(r.stdout).toContain('ready=0');
|
|
});
|
|
test('GSTACK_STRICT_BUILD=1 stops setup', () => {
|
|
const r = gate('1');
|
|
expect(r.status).toBe(1);
|
|
expect(r.stderr).toContain('CSO build completed without its required native artifact set (GSTACK_STRICT_BUILD=1)');
|
|
});
|
|
});
|