Files
gstack/test/upgrade-migration-v1.test.ts
T
Garry Tan 00a7a65026 test: V1 gate coverage — writing-style resolver + config + jargon + migration + dormancy
Six new gate-tier test files:

- test/writing-style-resolver.test.ts — asserts Writing Style section
  is injected into tier-≥2 preamble, all 6 rules present, jargon list
  inlined, terse-mode gate condition present, Codex output uses
  \$GSTACK_BIN (not ~/.claude/), tier-1 does NOT get the section,
  migration-prompt block present.

- test/explain-level-config.test.ts — gstack-config set/get round-trip
  for default + terse, unknown-value warns + defaults to default,
  header documents the key, round-trip across set→set→get.

- test/jargon-list.test.ts — shape + ~50 terms + no duplicates
  (case-insensitive) + includes canonical high-signal terms.

- test/v0-dormancy.test.ts — 5D dimension names + archetype names
  forbidden in default-mode tier-≥2 SKILL.md output, except for
  plan-tune and office-hours where they're load-bearing.

- test/readme-throughput.test.ts — script replaces anchor with number
  on happy path, writes PENDING marker when JSON missing, CI gate
  asserts committed README contains no PENDING string.

- test/upgrade-migration-v1.test.ts — fresh run writes pending flag,
  idempotent after user-answered, pre-existing explain_level counts
  as answered.

All 95 V1 test-expect() calls pass. Full suite: 0 failures.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 11:39:24 +08:00

77 lines
2.5 KiB
TypeScript

/**
* gstack-upgrade/migrations/v1.0.0.0.sh — writing style migration.
*
* Coverage:
* - Fresh state: writes the pending-prompt flag
* - Idempotent: second run does nothing if .writing-style-prompted exists
* - Pre-set explain_level: counts as answered (user already decided)
*/
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { spawnSync } from 'child_process';
const ROOT = path.resolve(import.meta.dir, '..');
const MIGRATION = path.join(ROOT, 'gstack-upgrade', 'migrations', 'v1.0.0.0.sh');
let tmpHome: string;
beforeEach(() => {
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-mig-test-'));
});
afterEach(() => {
fs.rmSync(tmpHome, { recursive: true, force: true });
});
function run(): { stdout: string; stderr: string; status: number } {
const res = spawnSync('bash', [MIGRATION], {
encoding: 'utf-8',
env: { ...process.env, GSTACK_HOME: tmpHome },
});
return {
stdout: (res.stdout ?? '').trim(),
stderr: (res.stderr ?? '').trim(),
status: res.status ?? -1,
};
}
describe('v1.0.0.0 upgrade migration', () => {
test('migration file exists and is executable', () => {
expect(fs.existsSync(MIGRATION)).toBe(true);
const stat = fs.statSync(MIGRATION);
// Owner execute bit should be set
expect(stat.mode & 0o100).toBeGreaterThan(0);
});
test('fresh state: writes pending-prompt flag', () => {
const result = run();
expect(result.status).toBe(0);
expect(fs.existsSync(path.join(tmpHome, '.writing-style-prompt-pending'))).toBe(true);
});
test('idempotent: second run after user answered is a no-op', () => {
// Simulate user answered: flag exists
fs.writeFileSync(path.join(tmpHome, '.writing-style-prompted'), '');
const result = run();
expect(result.status).toBe(0);
// No pending flag created
expect(fs.existsSync(path.join(tmpHome, '.writing-style-prompt-pending'))).toBe(false);
});
test('idempotent: pre-existing pending flag is not duplicated', () => {
// First run
run();
const firstStat = fs.statSync(path.join(tmpHome, '.writing-style-prompt-pending'));
// Second run — flag stays, no error
const result = run();
expect(result.status).toBe(0);
// Flag still exists; mtime may update but existence is stable
expect(fs.existsSync(path.join(tmpHome, '.writing-style-prompt-pending'))).toBe(true);
void firstStat;
});
});