mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-19 02:42:29 +08:00
feat: smart update check with auto-upgrade, snooze backoff, config CLI (v0.3.9) (#62)
* feat: add bin/gstack-config CLI for reading/writing ~/.gstack/config.yaml Simple get/set/list interface for persistent gstack configuration. Used by update-check and upgrade skill for auto_upgrade and update_check settings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: smart update check with 12h cache, snooze backoff, config disable - Reduce cache TTL from 24h to 12h for faster update detection - Add exponential snooze backoff: 24h → 48h → 1 week (resets on new version) - Add update_check: false config option to disable checks entirely - Clear snooze file on just-upgraded - 14 new tests covering snooze levels, expiry, corruption, and config paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: upgrade skill with auto-upgrade, 4-option prompt, vendored sync - Auto-upgrade mode via config or GSTACK_AUTO_UPGRADE=1 env var - 4-option AskUserQuestion: upgrade once, always, not now, never - Step 4.5: sync local vendored copy after upgrading primary install - Snooze write with escalating backoff on "Not now" - Update preamble text in gen-skill-docs for new upgrade flow - Regenerate all SKILL.md files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: simplify upgrade instructions, move auto-upgrade to completed README now points to /gstack-upgrade instead of long paste commands. Auto-upgrade TODO moved to Completed section (v0.3.8). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: bump version and changelog (v0.3.9) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ _UPD=$(~/.claude/skills/gstack/bin/gstack-update-check 2>/dev/null || .claude/sk
|
||||
[ -n "$_UPD" ] && echo "$_UPD" || true
|
||||
```
|
||||
|
||||
If output shows `UPGRADE_AVAILABLE <old> <new>`: read `~/.claude/skills/gstack/gstack-upgrade/SKILL.md` and follow the "Inline upgrade flow" (AskUserQuestion → upgrade if yes, `touch ~/.gstack/last-update-check` if no). If `JUST_UPGRADED <from> <to>`: tell user "Running gstack v{to} (just updated!)" and continue.
|
||||
If output shows `UPGRADE_AVAILABLE <old> <new>`: read `~/.claude/skills/gstack/gstack-upgrade/SKILL.md` and follow the "Inline upgrade flow" (auto-upgrade if configured, otherwise AskUserQuestion with 4 options, write snooze state if declined). If `JUST_UPGRADED <from> <to>`: tell user "Running gstack v{to} (just updated!)" and continue.
|
||||
|
||||
# browse: QA Testing & Dogfooding
|
||||
|
||||
|
||||
125
browse/test/gstack-config.test.ts
Normal file
125
browse/test/gstack-config.test.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Tests for bin/gstack-config bash script.
|
||||
*
|
||||
* Uses Bun.spawnSync to invoke the script with temp dirs and
|
||||
* GSTACK_STATE_DIR env override for full isolation.
|
||||
*/
|
||||
|
||||
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { mkdtempSync, writeFileSync, rmSync, readFileSync, existsSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { tmpdir } from 'os';
|
||||
|
||||
const SCRIPT = join(import.meta.dir, '..', '..', 'bin', 'gstack-config');
|
||||
|
||||
let stateDir: string;
|
||||
|
||||
function run(args: string[] = [], extraEnv: Record<string, string> = {}) {
|
||||
const result = Bun.spawnSync(['bash', SCRIPT, ...args], {
|
||||
env: {
|
||||
...process.env,
|
||||
GSTACK_STATE_DIR: stateDir,
|
||||
...extraEnv,
|
||||
},
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe',
|
||||
});
|
||||
return {
|
||||
exitCode: result.exitCode,
|
||||
stdout: result.stdout.toString().trim(),
|
||||
stderr: result.stderr.toString().trim(),
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
stateDir = mkdtempSync(join(tmpdir(), 'gstack-config-test-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(stateDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('gstack-config', () => {
|
||||
// ─── get ──────────────────────────────────────────────────
|
||||
test('get on missing file returns empty, exit 0', () => {
|
||||
const { exitCode, stdout } = run(['get', 'auto_upgrade']);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('get existing key returns value', () => {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), 'auto_upgrade: true\n');
|
||||
const { exitCode, stdout } = run(['get', 'auto_upgrade']);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('true');
|
||||
});
|
||||
|
||||
test('get missing key returns empty', () => {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), 'auto_upgrade: true\n');
|
||||
const { exitCode, stdout } = run(['get', 'nonexistent']);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('get returns last value when key appears multiple times', () => {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), 'foo: bar\nfoo: baz\n');
|
||||
const { exitCode, stdout } = run(['get', 'foo']);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('baz');
|
||||
});
|
||||
|
||||
// ─── set ──────────────────────────────────────────────────
|
||||
test('set creates file and writes key on missing file', () => {
|
||||
const { exitCode } = run(['set', 'auto_upgrade', 'true']);
|
||||
expect(exitCode).toBe(0);
|
||||
const content = readFileSync(join(stateDir, 'config.yaml'), 'utf-8');
|
||||
expect(content).toContain('auto_upgrade: true');
|
||||
});
|
||||
|
||||
test('set appends new key to existing file', () => {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), 'foo: bar\n');
|
||||
const { exitCode } = run(['set', 'auto_upgrade', 'true']);
|
||||
expect(exitCode).toBe(0);
|
||||
const content = readFileSync(join(stateDir, 'config.yaml'), 'utf-8');
|
||||
expect(content).toContain('foo: bar');
|
||||
expect(content).toContain('auto_upgrade: true');
|
||||
});
|
||||
|
||||
test('set replaces existing key in-place', () => {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), 'auto_upgrade: false\n');
|
||||
const { exitCode } = run(['set', 'auto_upgrade', 'true']);
|
||||
expect(exitCode).toBe(0);
|
||||
const content = readFileSync(join(stateDir, 'config.yaml'), 'utf-8');
|
||||
expect(content).toContain('auto_upgrade: true');
|
||||
expect(content).not.toContain('auto_upgrade: false');
|
||||
});
|
||||
|
||||
test('set creates state dir if missing', () => {
|
||||
const nestedDir = join(stateDir, 'nested', 'dir');
|
||||
const { exitCode } = run(['set', 'foo', 'bar'], { GSTACK_STATE_DIR: nestedDir });
|
||||
expect(exitCode).toBe(0);
|
||||
expect(existsSync(join(nestedDir, 'config.yaml'))).toBe(true);
|
||||
});
|
||||
|
||||
// ─── list ─────────────────────────────────────────────────
|
||||
test('list shows all keys', () => {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), 'auto_upgrade: true\nupdate_check: false\n');
|
||||
const { exitCode, stdout } = run(['list']);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain('auto_upgrade: true');
|
||||
expect(stdout).toContain('update_check: false');
|
||||
});
|
||||
|
||||
test('list on missing file returns empty, exit 0', () => {
|
||||
const { exitCode, stdout } = run(['list']);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
// ─── usage ────────────────────────────────────────────────
|
||||
test('no args shows usage and exits 1', () => {
|
||||
const { exitCode, stdout } = run([]);
|
||||
expect(exitCode).toBe(1);
|
||||
expect(stdout).toContain('Usage');
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync } from 'fs';
|
||||
import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync, mkdirSync, symlinkSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { tmpdir } from 'os';
|
||||
|
||||
@@ -38,6 +38,10 @@ function run(extraEnv: Record<string, string> = {}) {
|
||||
beforeEach(() => {
|
||||
gstackDir = mkdtempSync(join(tmpdir(), 'gstack-upd-test-'));
|
||||
stateDir = mkdtempSync(join(tmpdir(), 'gstack-state-test-'));
|
||||
// Link real gstack-config so update_check config check works
|
||||
const binDir = join(gstackDir, 'bin');
|
||||
mkdirSync(binDir);
|
||||
symlinkSync(join(import.meta.dir, '..', '..', 'bin', 'gstack-config'), join(binDir, 'gstack-config'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -45,6 +49,18 @@ afterEach(() => {
|
||||
rmSync(stateDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function writeSnooze(version: string, level: number, epochSeconds: number) {
|
||||
writeFileSync(join(stateDir, 'update-snoozed'), `${version} ${level} ${epochSeconds}`);
|
||||
}
|
||||
|
||||
function writeConfig(content: string) {
|
||||
writeFileSync(join(stateDir, 'config.yaml'), content);
|
||||
}
|
||||
|
||||
function nowEpoch(): number {
|
||||
return Math.floor(Date.now() / 1000);
|
||||
}
|
||||
|
||||
describe('gstack-update-check', () => {
|
||||
// ─── Path A: No VERSION file ────────────────────────────────
|
||||
test('exits 0 with no output when VERSION file is missing', () => {
|
||||
@@ -246,4 +262,154 @@ describe('gstack-update-check', () => {
|
||||
expect(third.exitCode).toBe(0);
|
||||
expect(third.stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
// ─── Snooze tests ───────────────────────────────────────────
|
||||
test('snoozed level 1 within 24h → silent (cached path)', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeSnooze('0.4.0', 1, nowEpoch() - 3600); // 1h ago (within 24h)
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('snoozed level 1 expired (25h ago) → outputs UPGRADE_AVAILABLE', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeSnooze('0.4.0', 1, nowEpoch() - 90000); // 25h ago
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('snoozed level 2 within 48h → silent', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeSnooze('0.4.0', 2, nowEpoch() - 86400); // 24h ago (within 48h)
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('snoozed level 2 expired (49h ago) → outputs', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeSnooze('0.4.0', 2, nowEpoch() - 176400); // 49h ago
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('snoozed level 3 within 7d → silent', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeSnooze('0.4.0', 3, nowEpoch() - 518400); // 6d ago (within 7d)
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('snoozed level 3 expired (8d ago) → outputs', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeSnooze('0.4.0', 3, nowEpoch() - 691200); // 8d ago
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('snooze ignored when version differs (new version resets snooze)', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.5.0');
|
||||
// Snoozed for 0.4.0, but remote is now 0.5.0
|
||||
writeSnooze('0.4.0', 3, nowEpoch() - 60); // very recent
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.5.0');
|
||||
});
|
||||
|
||||
test('corrupt snooze file → outputs normally', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeFileSync(join(stateDir, 'update-snoozed'), 'garbage');
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('non-numeric epoch in snooze file → outputs', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeFileSync(join(stateDir, 'update-snoozed'), '0.4.0 1 abc');
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('non-numeric level in snooze file → outputs', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
writeFileSync(join(stateDir, 'update-snoozed'), `0.4.0 abc ${nowEpoch()}`);
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('snooze respected on remote fetch path (no cache)', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(gstackDir, 'REMOTE_VERSION'), '0.4.0\n');
|
||||
// No cache file — goes to remote fetch path
|
||||
writeSnooze('0.4.0', 1, nowEpoch() - 3600); // 1h ago
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
// Cache should still be written
|
||||
const cache = readFileSync(join(stateDir, 'last-update-check'), 'utf-8');
|
||||
expect(cache).toContain('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
|
||||
test('just-upgraded clears snooze file', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.4.0\n');
|
||||
writeFileSync(join(stateDir, 'just-upgraded-from'), '0.3.3\n');
|
||||
writeSnooze('0.4.0', 2, nowEpoch() - 3600);
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('JUST_UPGRADED 0.3.3 0.4.0');
|
||||
expect(existsSync(join(stateDir, 'update-snoozed'))).toBe(false);
|
||||
});
|
||||
|
||||
// ─── Config tests ──────────────────────────────────────────
|
||||
test('update_check: false disables all checks', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(gstackDir, 'REMOTE_VERSION'), '0.4.0\n');
|
||||
writeConfig('update_check: false\n');
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('');
|
||||
// No cache should be written
|
||||
expect(existsSync(join(stateDir, 'last-update-check'))).toBe(false);
|
||||
});
|
||||
|
||||
test('missing config.yaml does not crash', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
writeFileSync(join(gstackDir, 'REMOTE_VERSION'), '0.4.0\n');
|
||||
// No config file — should behave normally
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.3.3 0.4.0');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user