mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 16:41:35 +01:00
Reader subagents on Capy stop sending telemetry, error runs report their error class, and test fixtures stop reading the owner's settings (#4597)
On a Capy machine, a shell that never loaded gstack's launch file (such as a review subagent's) now sends no usage data instead of falling back to the machine setting, as the privacy doc already promised. Error runs now fill the existing error_class field from their exit reason, and each setup step and outcome is reported at most once a day per install, so a loop rerunning setup no longer floods the counts. Tests no longer inherit the owner's preferences file, skill loadout or plugin state, which caused false failures. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/outside-voice#1 reader=outside-voice
This commit is contained in:
1 parent
09bd0fad0f
commit
19069a9810
13 files changed
+140
-8
No files matched your search
@@ -8,6 +8,7 @@ import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { CAPY_LAUNCH_MARKERS } from '../../scripts/lib/shard-engine';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..', '..');
|
||||
export const PREFLIGHT = path.join(ROOT, 'bin', 'gstack-ship-preflight');
|
||||
@@ -56,7 +57,8 @@ export function shipFixture(base: Record<string, string> = {}, feat: Record<stri
|
||||
must(gitIn(work, ['checkout', '-qb', 'feat']), 'branch');
|
||||
writeIn(work, feat);
|
||||
must(gitIn(work, ['add', '-A']), 'add feat'); must(gitIn(work, ['commit', '-qm', 'feat']), 'feat commit');
|
||||
const { GSTACK_SESSION_KIND: _k, GSTACK_HEADLESS: _h, OPENCLAW_SESSION: _o, CI: _c, GITHUB_ACTIONS: _g, ...ambient } = process.env;
|
||||
const { GSTACK_HEADLESS: _h, OPENCLAW_SESSION: _o, CI: _c, GITHUB_ACTIONS: _g, ...ambient } = process.env;
|
||||
for (const name of CAPY_LAUNCH_MARKERS) delete ambient[name];
|
||||
const env = { ...ambient, PATH: `${stub}:${process.env.PATH}`, GSTACK_STATE_ROOT: state, GSTACK_HOME: state, GIT_AUTHOR_NAME: 'Fixture', GIT_AUTHOR_EMAIL: 'fixture@example.com',
|
||||
GIT_COMMITTER_NAME: 'Fixture', GIT_COMMITTER_EMAIL: 'fixture@example.com', GIT_CONFIG_GLOBAL: path.join(root, 'gitconfig'), GSTACK_SESSION_KIND: 'interactive' };
|
||||
fs.writeFileSync(path.join(root, 'gitconfig'), '[commit]\n\tgpgsign = false\n');
|
||||
|
||||
@@ -181,11 +181,12 @@ describe('launch-env echo ratchet', () => {
|
||||
const installer = fs.readFileSync(path.join(ROOT, 'bin/gstack-capy-install'), 'utf8');
|
||||
expect(installer).toContain('LAUNCH_FILE="${VERDICT%.json}.env"');
|
||||
expect(installer).toContain('chmod 0600 "$tmp"');
|
||||
for (const name of CAPY_LAUNCH_MARKERS) expect(installer, name).toMatch(new RegExp(`^\\s*echo "export ${name}=`, 'm'));
|
||||
for (const name of CAPY_LAUNCH_MARKERS) expect(installer, name).toMatch(new RegExp(`echo "export ${name}=`));
|
||||
// Both directions: every `export NAME=` line the launch file writes is either a marker the shard
|
||||
// sandbox and the test preload strip, or GSTACK_STATE_ROOT, which they keep on purpose (GSTA-99).
|
||||
// The PATH prepend is a separate `case` line this regex ignores; PATH is kept too.
|
||||
const exported = [...installer.matchAll(/^\s*echo "export ([A-Z_]+)=/gm)].map(m => m[1]).sort();
|
||||
// The PATH prepend is a separate `case` line this regex ignores; PATH is kept too. Not anchored to the line
|
||||
// start: the preferences file and the loadout root are written by conditional lines (GSTA-666).
|
||||
const exported = [...installer.matchAll(/echo "export ([A-Z_]+)=/g)].map(m => m[1]).sort();
|
||||
expect(exported).toEqual([...CAPY_LAUNCH_MARKERS, 'GSTACK_STATE_ROOT'].sort());
|
||||
expect(installer).toContain('echo "GSTACK_LAUNCH_FILE: $LAUNCH_FILE"');
|
||||
for (const file of ['ship/sections/documentation.md', 'document-release/SKILL.md', 'autoplan/DRIVER.md', 'capy/skill/gstack/SKILL.md']) {
|
||||
|
||||
@@ -122,6 +122,13 @@ describe.skipIf(process.platform === 'win32')('gstack-skill-end next fields', ()
|
||||
expect(e.harness_session_id).not.toBe('aaaaaaaaaaaaaaaa');
|
||||
}, 30_000);
|
||||
|
||||
test('an error run sends its exit reason as error_class, from the same fixed list; other runs and reasons send none', async () => {
|
||||
const end = (outcome: string, reason: string) => run('gstack-skill-end', ['--skill', 'qa', '--outcome', outcome, '--session-id', '99-1', '--exit-reason', reason]);
|
||||
end('error', 'test_failed'); end('error', 'made_up'); end('error', 'completed'); end('success', 'tool_error');
|
||||
const rows = await eventually(4);
|
||||
expect(rows.map(e => e.error_class)).toEqual(['test_failed', null, null, null]);
|
||||
});
|
||||
|
||||
test('an unknown start time sends a null duration, not 0', async () => {
|
||||
const out = run('gstack-skill-end', ['--skill', 'qa', '--outcome', 'success', '--session-id', '99-1']);
|
||||
expect(out).toContain('duration_s=unknown');
|
||||
|
||||
@@ -12,6 +12,8 @@ import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { readConfigKey } from '../lib/state-root';
|
||||
import { repoPolicyTier, repoPolicyTierBatch } from '../lib/gbrain-repo-policy-client';
|
||||
import { CAPY_LAUNCH_MARKERS } from '../scripts/lib/shard-engine';
|
||||
import { shipFixture } from './helpers/ship-bin-fixture';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const CONFIG = path.join(ROOT, 'bin', 'gstack-config');
|
||||
@@ -164,6 +166,39 @@ describe('test preload hermeticity', () => {
|
||||
expect(r.stderr.match(/test-setup: stripped/g)?.length).toBe(2);
|
||||
});
|
||||
|
||||
test('bun test strips every variable the Capy launch file exports and the plugin state root (GSTA-666)', () => {
|
||||
const exported = [...fs.readFileSync(path.join(ROOT, 'bin', 'gstack-capy-install'), 'utf-8').matchAll(/echo "export (GSTACK_[A-Z_]+)=/g)].map(m => m[1]);
|
||||
expect(exported).toEqual(expect.arrayContaining(['GSTACK_STATE_ROOT', 'GSTACK_CAPY', 'GSTACK_PREFERENCES_FILE', 'GSTACK_LOADOUT_SKILL_ROOT']));
|
||||
const leaked = [...new Set([...exported, 'CLAUDE_PLUGIN_DATA'])].filter(k => k !== 'GSTACK_HOME');
|
||||
const probe = path.join(tmp, 'launch-probe.test.ts');
|
||||
fs.writeFileSync(probe, [
|
||||
"import { test, expect } from 'bun:test';",
|
||||
"import { resolveStateRoot } from '" + path.join(ROOT, 'lib', 'state-root.ts').replace(/\\/g, '/') + "';",
|
||||
"test('probe', () => {",
|
||||
` expect(${JSON.stringify(leaked)}.filter(k => process.env[k] !== undefined)).toEqual([]);`,
|
||||
" expect(resolveStateRoot()).toBe(process.env.GSTACK_HOME);",
|
||||
"});",
|
||||
].join('\n'));
|
||||
const r = spawnSync('bun', ['test', '--preload', path.join(ROOT, 'test-setup.ts'), probe], {
|
||||
cwd: tmp,
|
||||
env: { ...env, ...Object.fromEntries(leaked.map(k => [k, path.join(tmp, 'real-root')])), GSTACK_HOME: resolved, CLAUDE_PLUGIN_ROOT: path.join(tmp, 'plugins', 'gstack') },
|
||||
encoding: 'utf-8',
|
||||
timeout: 60_000,
|
||||
});
|
||||
expect([r.status, r.stderr.match(/\(fail\)|error:.*$/gm)], r.stderr).toEqual([0, null]);
|
||||
});
|
||||
|
||||
test.skipIf(process.platform === 'win32')('the ship bin fixture hands its children no launch marker, even without the preload (GSTA-666)', () => {
|
||||
const saved = Object.fromEntries(CAPY_LAUNCH_MARKERS.map(k => [k, process.env[k]]));
|
||||
for (const k of CAPY_LAUNCH_MARKERS) process.env[k] = 'leaked';
|
||||
let f: ReturnType<typeof shipFixture>;
|
||||
try { f = shipFixture(); } finally { for (const [k, v] of Object.entries(saved)) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } }
|
||||
try {
|
||||
const r = f.run(process.execPath, ['-e', `console.log(${JSON.stringify(CAPY_LAUNCH_MARKERS)}.filter(k => process.env[k] === 'leaked').join(','))`]);
|
||||
expect(r.stdout.trim()).toBe('');
|
||||
} finally { f.cleanup(); }
|
||||
});
|
||||
|
||||
test('bun test strips an inherited live-brain URL, so a temp-HOME gbrain child never sees it (#3466)', () => {
|
||||
const live = path.join(tmp, 'live-gbrain');
|
||||
fs.mkdirSync(live, { recursive: true });
|
||||
|
||||
@@ -129,6 +129,39 @@ describe.skipIf(process.platform === 'win32')('Capy telemetry opt-in', () => {
|
||||
expect(skillEnd({ GSTACK_CAPY: '' })).toContain('ARTIFACTS_SYNC: skipped (unattended session)');
|
||||
});
|
||||
|
||||
test('a shell on a Capy install that never sourced the launch file (a reader subagent) sends nothing, whatever the machine tier', () => {
|
||||
const install = path.join(tmp, 'install');
|
||||
fs.mkdirSync(install);
|
||||
execSync('git init -q', { cwd: install, timeout: 20_000 });
|
||||
fs.symlinkSync(BIN, path.join(install, 'bin'));
|
||||
fs.copyFileSync(path.join(ROOT, 'VERSION'), path.join(install, 'VERSION'));
|
||||
run(`${BIN}/gstack-config set telemetry community`, { GSTACK_SESSION_KIND: 'interactive' });
|
||||
const reader = { GSTACK_DIR: install, GSTACK_SESSION_KIND: 'interactive', GSTACK_CAPY: '' };
|
||||
const end = () => run(`${install}/bin/gstack-skill-end --skill plan-ceo-review --outcome success --session-id 123-reader --tel-start 1`, reader);
|
||||
end();
|
||||
expect(sent().filter(e => e.v === 1).map(e => e.source)).toEqual(['live']);
|
||||
fs.rmSync(path.join(tmp, 'sent'));
|
||||
fs.rmSync(path.join(tmp, 'analytics'), { recursive: true, force: true }); fs.mkdirSync(path.join(tmp, 'analytics'));
|
||||
fs.writeFileSync(path.join(install, '.git', 'gstack-capy-install.state'), 'fixture\n');
|
||||
end();
|
||||
expect(sent()).toEqual([]);
|
||||
expect(run(`${install}/bin/gstack-telemetry-tier`, reader)).toBe('off');
|
||||
expect(run(`${install}/bin/gstack-telemetry-tier`, { GSTACK_DIR: install })).toBe('anonymous');
|
||||
});
|
||||
|
||||
test('a host directory that links only bin/ to a Capy install (Codex) still sees the install and sends nothing', () => {
|
||||
const install = path.join(tmp, 'install');
|
||||
fs.mkdirSync(path.join(install, 'bin'), { recursive: true });
|
||||
execSync('git init -q', { cwd: install, timeout: 20_000 });
|
||||
for (const f of fs.readdirSync(BIN)) fs.symlinkSync(path.join(BIN, f), path.join(install, 'bin', f));
|
||||
fs.writeFileSync(path.join(install, '.git', 'gstack-capy-install.state'), 'fixture\n');
|
||||
const host = path.join(tmp, 'codex-skill');
|
||||
fs.mkdirSync(host);
|
||||
fs.symlinkSync(path.join(install, 'bin'), path.join(host, 'bin'));
|
||||
run(`${BIN}/gstack-config set telemetry community`, { GSTACK_SESSION_KIND: 'interactive' });
|
||||
expect(run(`${host}/bin/gstack-telemetry-tier`, { GSTACK_SESSION_KIND: 'interactive', GSTACK_CAPY: '' })).toBe('off');
|
||||
});
|
||||
|
||||
test('gstack-telemetry-tier prints the Capy opt-in alone with --capy, else the machine setting', () => {
|
||||
const tier = (args = '', extra: Record<string, string> = {}) => run(`${path.join(BIN, 'gstack-telemetry-tier')} ${args}`, extra);
|
||||
run(`${BIN}/gstack-config set telemetry community`, { GSTACK_SESSION_KIND: 'interactive' });
|
||||
|
||||
@@ -395,6 +395,29 @@ describe('.pending marker', () => {
|
||||
expect(events[0].outcome).toBe('chromium-install');
|
||||
});
|
||||
|
||||
test('each onboarding step is recorded at most once a day, however often setup reruns', () => {
|
||||
setConfig('telemetry', 'community');
|
||||
for (let i = 0; i < 3; i++) run(`${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_playwright --outcome chromium-install --no-sweep`);
|
||||
run(`${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_welcome --outcome shown --no-sweep`);
|
||||
run(`${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_welcome --outcome shown --no-sweep`);
|
||||
expect(parseJsonl().map(e => e.skill)).toEqual(['_setup_playwright', '_setup_welcome']);
|
||||
});
|
||||
|
||||
test('a different onboarding outcome for the same step on the same day is still recorded', () => {
|
||||
setConfig('telemetry', 'community');
|
||||
run(`${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_playwright --outcome chromium-install --no-sweep`);
|
||||
run(`${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_playwright --outcome deps-missing --no-sweep`);
|
||||
run(`${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_playwright --outcome deps-missing --no-sweep`);
|
||||
expect(parseJsonl().map(e => e.outcome)).toEqual(['chromium-install', 'deps-missing']);
|
||||
});
|
||||
|
||||
test('concurrent setup runs record an onboarding step once', () => {
|
||||
setConfig('telemetry', 'community');
|
||||
const one = `${BIN}/gstack-telemetry-log --event-type onboarding --skill _setup_playwright --outcome chromium-install --no-sweep`;
|
||||
run(`for i in $(seq 1 24); do ${one} & done; wait`);
|
||||
expect(parseJsonl().map(e => e.outcome)).toEqual(['chromium-install']);
|
||||
});
|
||||
|
||||
test('finalizes stale .pending from another session as outcome:unknown', () => {
|
||||
setConfig('telemetry', 'anonymous');
|
||||
|
||||
|
||||
Reference in new issue
Block a user