mirror of
https://github.com/garrytan/gstack.git
synced 2026-08-31 02:10:51 +02:00
* fix(browse): never chmod shared, symlinked, or foreign-owned dirs to 0700 restrictDirectoryPermissions unconditionally chmodded its target. On hosts where the process holds CAP_FOWNER (Docker as root, CI sandboxes) that chmod SUCCEEDS on root-owned /tmp whenever a state file is configured there (BROWSE_STATE_FILE=/tmp/x.json derives stateDir=/tmp), and a 0700 /tmp breaks access(2)-based checks machine-wide for every other process. The POSIX branch now refuses shared sticky dirs, world-writable mounts under root, foreign-owned dirs, and symlinked state dirs; refusals warn once per process instead of failing silent; owned-but-unreadable dirs keep their chmod self-repair; and the check-then-act race is closed with fd-anchored O_NOFOLLOW + fstat/fchmod on a single inode. Regression tests cover the sticky-dir, foreign-uid, mkdirSecure-reapply, and symlinked-dir shapes. * fix: hash with sha256sum before shasum on Linux (config slugs + setup verify) shasum is perl/macOS; coreutils-only Linux ships sha256sum. Two call sites hard-coded shasum: gstack-config's sha8_of/sha16 (so resolve-user-slug exited 127 for any Linux user with a git email, the Layer-3 fallback) and the generated bun-installer checksum snippet in the browse/qa NEEDS_SETUP flow (spurious "checksum mismatch" on the same distros). Both now resolve sha256sum first and fall back to shasum -a 256. New shim-PATH tests pin BOTH hasher branches of sha8_of to a known vector and cover the sha8->sha16 collision escalation end to end. * feat(contract): Aside is the recommended driver for third-party web actions The Third-Party Web Actions contract (ship, spec, office-hours, land-and-deploy, setup-deploy) now names the Aside AI browser as the recommended driver: it acts across the user's real logged-in sessions, which is what vendor-dashboard moments need. Supersedes the v1.65.0.0 de-Aside stance by explicit user directive (2026-08-27). Detection is a runtime probe (command -v + aside --version under a portable gtimeout/timeout/bare guard; nonzero exit = not detected). Consent options render per detection state with Aside recommended and the first-party stack ($B headed + handoff, GStack Browser) as the universal fallback. Absent on macOS, the contract mentions the aside.com download (macOS 15+) once per task; gstack never runs an installer and binary presence is never consent. Drive discipline: step-wise over whole-task delegation, vendor confirm mode on, vendor skill/--help text scoped to operational syntax only, secrets minimized (autofill / human-used copy buttons), Apple credential creation never a drive target in any skill, failure path quotes redacted errors and falls back only with fresh consent. test/third-party-actions.test.ts pins every load-bearing sentence (21 tests) plus repo-wide tripwires: an aside command allowlist (--version/--help only, code spans AND prose) and a ban on Aside installer invocations across all generated docs. Budget ratchet fixture and carve skeleton ceilings refreshed in this commit per the ratchet protocol. * chore: regenerate remaining browse-setup snippet consumers The sha256sum-first checksum fallback in the generated NEEDS_SETUP snippet renders into every browse-consuming skill, not just browse/qa. Mechanical regen of the other ten consumers; no template changes here. * test: consent-gate E2E suite + functional fs-capability probes Five hermetic gate-tier E2E cases (tpa-present / absent-linux / broken / absent-darwin / apple-ban) drive the real contract section through claude -p with PATH shims for aside and uname; the absent cases filter any REAL aside binary out of the child PATH and assert absence with Bun.which before spawning, so dev machines cannot leak into detection. Registered per-case in E2E_TOUCHFILES/E2E_TIERS with template-level deps (ship/SKILL.md.tmpl, gen-skill-docs.ts) and added to the evals.yml matrix with tier: gate. eval:bg:periodic's detach timeout rises to 36000s for the grown periodic shard census (floor-enforced by test/eval-detach-timeout-floor.test.ts); CLAUDE.md doc updated to match. test/helpers/fs-caps.ts adds canRevokeWrites/canRevokeReads functional probes; 13 chmod-based tests swap their uid-0-only guards for the probes so suites skip honestly on CAP_DAC_OVERRIDE containers (this sandbox: uid 1000 with full caps) instead of asserting revocations the kernel ignores. path-validation's symlink test targets /etc/passwd (exists everywhere; /etc/crontab is absent on Amazon Linux). * docs: file the Aside follow-ups in TODOS Phase-2 QA logged-in-evidence path (P3), a hostile-vendor-skill E2E for the contract's override sentence (P2), and fd-anchoring the file-level permission writes to match the directory hardening (P3). * chore: bump version and changelog (v1.72.0.0) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: update project documentation for v1.72.0.0 docs/skills.md: Third-Party Web Actions subsection under /ship (Aside recommended driver, consent rules, credential boundaries). BROWSER.md: "Aside and third-party drives" subsection under Real-browser mode + ToC entry, including the no-gstack-side-audit-trail caveat (ship adversarial finding 12). TODOS.md: mark the finding-12 doc note done. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: apply cross-model doc review fixes for v1.72.0.0 docs/skills.md: restore the /ship closing line above the new subsection. BROWSER.md: ToC label matches the heading; BROWSE_STATE_FILE env row documents the new dir-hardening refusal + one-time warning. CHANGELOG: correct the hasher precedence wording (sha256sum first, shasum fallback) and the fs-caps count (14 test files, verified against the diff). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: close cross-model doc-review gaps for v1.72.0.0 setup's manual bun-verify instruction gets the same sha256sum-first fallback the automated snippet got (coreutils-only Linux); BROWSER.md's BROWSE_STATE_FILE row now lists the under-root world-writable refusal; test-cost ceilings in CLAUDE.md/CONTRIBUTING.md updated for the five new gate E2E cases (~$4.20 E2E / ~$4.35 evals). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(test): gate the symlink-refusal test to POSIX and drop the umask assumption The symlink regression test exercised the POSIX O_NOFOLLOW branch but ran on Windows, where restrictDirectoryPermissions takes the icacls branch and stat has no POSIX modes (0o666 always) — windows-free-tests failed on mode 493 vs 438. Early-return on win32 like every sibling test in the file, and assert the target's mode is UNCHANGED (captured post-mkdir) instead of hardcoding 0o755, which a strict umask would also break. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
327 lines
9.9 KiB
TypeScript
327 lines
9.9 KiB
TypeScript
/**
|
|
* gstack-upgrade/migrations/v1.40.0.0.sh — migration script unit tests.
|
|
*
|
|
* Per #1581: the original script unconditionally `touch`ed its done-marker even
|
|
* when the jq-gated privacy-map patch was skipped. The fix defers `touch ${DONE}`
|
|
* until every required repair either succeeded or was provably unnecessary.
|
|
*
|
|
* The "regression case" that this file pins is case 2: jq missing + privacy-map
|
|
* present → no done-marker. Against the buggy script, case 2 fails (marker is
|
|
* written despite skipped patch); against the fix it passes.
|
|
*
|
|
* Strategy: each test sets up an isolated tmpHome with controlled fixture
|
|
* content, and runs the migration via `spawnSync('bash', [MIGRATION], …)`.
|
|
* For "jq missing" we point PATH at a curated dir of symlinks to the standard
|
|
* utilities the script uses, omitting jq. For "jq mutation fails" we point PATH
|
|
* at a dir containing a jq shim that exits 1.
|
|
*/
|
|
|
|
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
import { canRevokeWrites } from "./helpers/fs-caps";
|
|
import * as fs from "fs";
|
|
import * as os from "os";
|
|
import * as path from "path";
|
|
import { spawnSync } from "child_process";
|
|
|
|
const ROOT = path.resolve(import.meta.dir, "..");
|
|
const MIGRATION = path.join(
|
|
ROOT,
|
|
"gstack-upgrade",
|
|
"migrations",
|
|
"v1.40.0.0.sh",
|
|
);
|
|
|
|
const NEW_PATTERN = "projects/*/*-eng-review-test-plan-*.md";
|
|
const REAL_PATH = "/usr/bin:/bin:/opt/homebrew/bin";
|
|
|
|
let tmpHome: string;
|
|
let gstackHome: string;
|
|
let migrationDir: string;
|
|
let donePath: string;
|
|
let allowlistPath: string;
|
|
let privacyPath: string;
|
|
let gitattrsPath: string;
|
|
|
|
beforeEach(() => {
|
|
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "gstack-mig-v1400-"));
|
|
gstackHome = path.join(tmpHome, ".gstack");
|
|
migrationDir = path.join(gstackHome, ".migrations");
|
|
donePath = path.join(migrationDir, "v1.40.0.0.done");
|
|
allowlistPath = path.join(gstackHome, ".brain-allowlist");
|
|
privacyPath = path.join(gstackHome, ".brain-privacy-map.json");
|
|
gitattrsPath = path.join(gstackHome, ".gitattributes");
|
|
fs.mkdirSync(gstackHome, { recursive: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
try {
|
|
fs.chmodSync(gstackHome, 0o755);
|
|
if (fs.existsSync(allowlistPath)) fs.chmodSync(allowlistPath, 0o644);
|
|
if (fs.existsSync(privacyPath)) fs.chmodSync(privacyPath, 0o644);
|
|
if (fs.existsSync(gitattrsPath)) fs.chmodSync(gitattrsPath, 0o644);
|
|
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
} catch {}
|
|
});
|
|
|
|
/**
|
|
* Construct a PATH-style directory of symlinks to standard utilities the
|
|
* migration script needs (mkdir, grep, sed, mv, rm, mktemp, cat, touch, printf,
|
|
* command, etc.). Optionally omit jq, or substitute a shim.
|
|
*/
|
|
function makeCuratedPath(opts: { jq?: "missing" | "shim-fail" | "real" } = {}): string {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "gstack-mig-path-"));
|
|
const utils = [
|
|
"bash",
|
|
"sh",
|
|
"mkdir",
|
|
"grep",
|
|
"sed",
|
|
"mv",
|
|
"rm",
|
|
"mktemp",
|
|
"cat",
|
|
"touch",
|
|
"printf",
|
|
"command",
|
|
"echo",
|
|
"test",
|
|
"[",
|
|
"tee",
|
|
"true",
|
|
"false",
|
|
"ls",
|
|
"chmod",
|
|
];
|
|
const realDirs = REAL_PATH.split(":");
|
|
for (const u of utils) {
|
|
for (const d of realDirs) {
|
|
const src = path.join(d, u);
|
|
if (fs.existsSync(src)) {
|
|
try {
|
|
fs.symlinkSync(src, path.join(dir, u));
|
|
} catch {}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
const jq = opts.jq ?? "real";
|
|
if (jq === "real") {
|
|
for (const d of realDirs) {
|
|
const src = path.join(d, "jq");
|
|
if (fs.existsSync(src)) {
|
|
try {
|
|
fs.symlinkSync(src, path.join(dir, "jq"));
|
|
} catch {}
|
|
break;
|
|
}
|
|
}
|
|
} else if (jq === "shim-fail") {
|
|
const shim = path.join(dir, "jq");
|
|
fs.writeFileSync(
|
|
shim,
|
|
`#!/usr/bin/env bash\necho "fake jq: refusing" >&2\nexit 1\n`,
|
|
{ mode: 0o755 },
|
|
);
|
|
}
|
|
// jq === "missing" → don't add anything
|
|
return dir;
|
|
}
|
|
|
|
function run(opts: { path?: string } = {}) {
|
|
const env = {
|
|
HOME: tmpHome,
|
|
PATH: opts.path ?? REAL_PATH,
|
|
};
|
|
return spawnSync("bash", [MIGRATION], {
|
|
env,
|
|
encoding: "utf-8",
|
|
cwd: tmpHome,
|
|
});
|
|
}
|
|
|
|
function freshPrivacyMap() {
|
|
fs.writeFileSync(
|
|
privacyPath,
|
|
JSON.stringify(
|
|
[{ pattern: "projects/*/*-some-other-*.md", class: "artifact" }],
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
}
|
|
|
|
function freshAllowlist() {
|
|
fs.writeFileSync(
|
|
allowlistPath,
|
|
"# header\nprojects/*/*-some-other-*.md\n# ---- USER ADDITIONS BELOW\n",
|
|
);
|
|
}
|
|
|
|
function freshGitattrs() {
|
|
fs.writeFileSync(gitattrsPath, "projects/*/*-some-other-*.md merge=union\n");
|
|
}
|
|
|
|
describe("migrations/v1.40.0.0.sh", () => {
|
|
test("case 1: jq present, fresh privacy-map — all three files patched, marker written", () => {
|
|
freshAllowlist();
|
|
freshPrivacyMap();
|
|
freshGitattrs();
|
|
|
|
const r = run();
|
|
|
|
expect(r.status).toBe(0);
|
|
expect(fs.existsSync(donePath)).toBe(true);
|
|
|
|
const allowlist = fs.readFileSync(allowlistPath, "utf-8");
|
|
expect(allowlist).toContain(NEW_PATTERN);
|
|
|
|
const privacy = JSON.parse(fs.readFileSync(privacyPath, "utf-8"));
|
|
expect(
|
|
privacy.some(
|
|
(e: any) => e.pattern === NEW_PATTERN && e.class === "artifact",
|
|
),
|
|
).toBe(true);
|
|
|
|
const gitattrs = fs.readFileSync(gitattrsPath, "utf-8");
|
|
expect(gitattrs).toContain(`${NEW_PATTERN} merge=union`);
|
|
});
|
|
|
|
test("case 2 (regression for #1581): jq missing, privacy-map exists — marker NOT written, text patches still applied", () => {
|
|
freshAllowlist();
|
|
freshPrivacyMap();
|
|
freshGitattrs();
|
|
|
|
const noJq = makeCuratedPath({ jq: "missing" });
|
|
const r = run({ path: noJq });
|
|
|
|
expect(r.status).toBe(0);
|
|
expect(r.stderr).toMatch(/jq not found/);
|
|
|
|
// Done-marker must NOT be written — this is the whole point of the fix.
|
|
expect(fs.existsSync(donePath)).toBe(false);
|
|
|
|
// Text-only patches still landed (they don't need jq).
|
|
expect(fs.readFileSync(allowlistPath, "utf-8")).toContain(NEW_PATTERN);
|
|
expect(fs.readFileSync(gitattrsPath, "utf-8")).toContain(
|
|
`${NEW_PATTERN} merge=union`,
|
|
);
|
|
|
|
// Privacy-map untouched (still missing the new entry).
|
|
const privacy = JSON.parse(fs.readFileSync(privacyPath, "utf-8"));
|
|
expect(privacy.some((e: any) => e.pattern === NEW_PATTERN)).toBe(false);
|
|
});
|
|
|
|
test("case 3: jq missing, then jq restored — second run completes patch and writes marker", () => {
|
|
freshAllowlist();
|
|
freshPrivacyMap();
|
|
freshGitattrs();
|
|
|
|
// First run with jq missing
|
|
const noJq = makeCuratedPath({ jq: "missing" });
|
|
const r1 = run({ path: noJq });
|
|
expect(r1.status).toBe(0);
|
|
expect(fs.existsSync(donePath)).toBe(false);
|
|
|
|
// Second run with jq restored
|
|
const r2 = run();
|
|
expect(r2.status).toBe(0);
|
|
expect(fs.existsSync(donePath)).toBe(true);
|
|
|
|
const privacy = JSON.parse(fs.readFileSync(privacyPath, "utf-8"));
|
|
expect(
|
|
privacy.some(
|
|
(e: any) => e.pattern === NEW_PATTERN && e.class === "artifact",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
test("case 4: jq present, privacy-map already has correct entry — idempotent, marker written", () => {
|
|
freshAllowlist();
|
|
fs.writeFileSync(
|
|
privacyPath,
|
|
JSON.stringify(
|
|
[{ pattern: NEW_PATTERN, class: "artifact" }],
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
freshGitattrs();
|
|
|
|
const r = run();
|
|
expect(r.status).toBe(0);
|
|
expect(fs.existsSync(donePath)).toBe(true);
|
|
|
|
const privacy = JSON.parse(fs.readFileSync(privacyPath, "utf-8"));
|
|
const matches = privacy.filter((e: any) => e.pattern === NEW_PATTERN);
|
|
expect(matches.length).toBe(1);
|
|
expect(matches[0].class).toBe("artifact");
|
|
});
|
|
|
|
test("case 5: jq present, privacy-map file missing — allowlist + gitattrs patched, marker written", () => {
|
|
freshAllowlist();
|
|
// No privacy-map file
|
|
freshGitattrs();
|
|
|
|
const r = run();
|
|
expect(r.status).toBe(0);
|
|
expect(fs.existsSync(donePath)).toBe(true);
|
|
expect(fs.existsSync(privacyPath)).toBe(false);
|
|
|
|
expect(fs.readFileSync(allowlistPath, "utf-8")).toContain(NEW_PATTERN);
|
|
expect(fs.readFileSync(gitattrsPath, "utf-8")).toContain(
|
|
`${NEW_PATTERN} merge=union`,
|
|
);
|
|
});
|
|
|
|
test("case 6: jq present, privacy-map JSON malformed — no marker, error logged, no mutation", () => {
|
|
freshAllowlist();
|
|
fs.writeFileSync(privacyPath, "{ this is not json [");
|
|
freshGitattrs();
|
|
|
|
const r = run();
|
|
expect(r.status).toBe(0);
|
|
// No marker — broken JSON should NOT be papered over.
|
|
expect(fs.existsSync(donePath)).toBe(false);
|
|
// Privacy-map content untouched.
|
|
expect(fs.readFileSync(privacyPath, "utf-8")).toBe("{ this is not json [");
|
|
});
|
|
|
|
test("case 7: jq present but mutation fails (shim exit 1) — no marker, tempfile cleaned up", () => {
|
|
freshAllowlist();
|
|
freshPrivacyMap();
|
|
freshGitattrs();
|
|
|
|
const fakeJq = makeCuratedPath({ jq: "shim-fail" });
|
|
const r = run({ path: fakeJq });
|
|
|
|
expect(r.status).toBe(0);
|
|
expect(fs.existsSync(donePath)).toBe(false);
|
|
|
|
// Tempfile cleanup: no leftover *.tmp.* sidecars.
|
|
const leftovers = fs
|
|
.readdirSync(gstackHome)
|
|
.filter((n) => n.startsWith(".brain-privacy-map.json.tmp."));
|
|
expect(leftovers.length).toBe(0);
|
|
});
|
|
|
|
test("case 8: allowlist append fails (read-only file, no USER ADDITIONS marker) — no marker, warn logged", () => {
|
|
if (!canRevokeWrites()) return; // chmod is advisory here (win32, root, DAC-override containers)
|
|
// Allowlist WITHOUT the "# ---- USER ADDITIONS BELOW" marker — the script
|
|
// falls into the plain `printf >>` append path. Make the file read-only
|
|
// so the append fails (sed -i.bak on macOS silently no-ops on read-only
|
|
// files, so we have to take the printf path to exercise this).
|
|
fs.writeFileSync(
|
|
allowlistPath,
|
|
"# header\nprojects/*/*-some-other-*.md\n",
|
|
);
|
|
freshPrivacyMap();
|
|
freshGitattrs();
|
|
fs.chmodSync(allowlistPath, 0o444);
|
|
|
|
const r = run();
|
|
expect(r.status).toBe(0);
|
|
// Marker must NOT be written when a required repair failed.
|
|
expect(fs.existsSync(donePath)).toBe(false);
|
|
});
|
|
});
|