gstack-game
gstack-game copied to clipboard
test: security regression tests for telemetry and review-log
Problem
gstack-game's #23 added security hardening (json_safe, JSON.parse gate, random UUID, duration validation) but with zero regression tests. If someone accidentally removes the sanitization, nothing catches it.
gstack upstream has 20 security regression tests across 7 test files (PR #595, v0.13.1.0) plus 6 audit compliance tests (PR #574).
What to do
Add regression tests to `test/` that verify:
telemetry-log tests
- `json_safe()` strips quotes from input
- `json_safe()` strips backslashes
- `json_safe()` strips control characters (\n, \r, \t)
- `json_safe()` caps output at 200 chars
- Duration rejects negative values
- Duration caps at 86400
- Installation ID file is created on first run
- Installation ID is reused on subsequent runs
review-log tests
- Valid JSON is accepted
- Malformed JSON is rejected with non-zero exit
- JSON with injection payload is rejected
preamble tests
- Telemetry line uses `_SLUG_SAFE` not `_SLUG`
- Telemetry line uses `_BRANCH_SAFE` not `_BRANCH`
Implementation
Create `test/security.test.ts` with bash-level tests:
- Use `execSync` to invoke bin/ scripts with test inputs
- Use temp directories for state isolation
- Verify JSONL output is valid JSON
Upstream Reference
- gstack PR #595: 20 tests in `test/telemetry.test.ts`, `browse/test/adversarial-security.test.ts`, etc.
- gstack PR #574: 6 tests in `test/audit-compliance.test.ts`
Effort: MEDIUM
New test file, ~150 lines. No production code changes.