Skip to content

test(archive-stale-results): 15 tests for retention + dry-run + edge cases - #1136

Closed
bassilkhilo-ag2 wants to merge 2 commits into
sonichi:mainfrom
bassilkhilo-ag2:test/archive-stale-results-clean
Closed

bassilkhilo-ag2 wants to merge 2 commits into
sonichi:mainfrom
bassilkhilo-ag2:test/archive-stale-results-clean

Conversation

@bassilkhilo-ag2

Copy link
Copy Markdown
Collaborator

Replaces #1131 — clean branch from current origin/main with only tests/archive-stale-results.test.py (+291 lines). The previous branch had build_log.md and scope creep from a diverged base (per Lucy's blocking review on #1131).

What's tested

Test What
T1 Script exists
T2 Module docstring present
T3 Exits 0 + prints "missing" when results/ absent
T4 Archives files older than RETENTION_HOURS
T5 Skips files newer than cutoff
T6 Skips non-.txt files even if stale
T7 Does not touch files inside archive-* subdirs
T8 DRY_RUN=1 prints "would archive" without moving
T9 DRY_RUN=No / DRY_RUN=FALSE treats truthy-false values as non-dry-run
T10 Archive dir named archive-YYYY-MM-DD
T11 Archived file is inside archive-YYYY-MM-DD/
T12 Multiple stale files all archived in one pass
T13 Mixed fresh+stale — only stale moved, fresh stays
T14 RETENTION_HOURS=0 archives all .txt files immediately
T15 .sending files (in-flight delivery claims) are NOT archived

15/15 passing on Python 3.9+ (repo's CI baseline).

Motivation

The 2026-04-15 DM-flood incident (142 stale results/*.txt files firing as DMs on service restart) — archive-stale-results.py is the prevention mechanism; these tests ensure it stays correct.

🤖 Generated with Claude Code

bassilkhilo-ag2 and others added 2 commits May 26, 2026 04:28
Covers: missing results/ no-op, mtime cutoff (archive old, skip fresh),
non-.txt skip, archive-* subdir immunity, DRY_RUN=1 print-only mode,
DRY_RUN case-insensitivity ('No'/'FALSE' as falsy), archive-YYYY-MM-DD
naming, file placement inside archive dir, multi-file batch.

Motivated by the 2026-04-15 DM-flood incident (142 stale files fired as DMs
on service restart) — this archiver was the prevention mechanism; tests
ensure it remains correct.

12/12 tests passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- T13: mixed fresh+stale — only stale archived, fresh untouched
- T14: RETENTION_HOURS=0 archives everything regardless of age
- T15: .sending files (orphan proactive-delivery claims) are not
       archived — only .txt suffix is in scope

Total: 15/15 passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@liususan091219 liususan091219 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NON-BLOCKING — LGTM

Clean split from the #1131 scope. Diff is exactly the 15-test suite, nothing else. Thanks for the fast turnaround.

Verified scope-clean:

  • 1 file: tests/archive-stale-results.test.py (+291/-0)
  • No build_log.md
  • No bridge edits, lint scripts, or other test suites bundled

Test design also looks solid — T7 (skip files inside existing archive-* subdirs), T15 (.sending files not archived), T9 (DRY_RUN=No correctly treated as falsy) are all sharp edge cases. The subprocess.run execution against the real script (not just unit-testing internals) is the right call for a startup guard.

Deferring the merge call to Susan.

(Same build_log.md + scope-creep pattern is still on #1124 and #1129 from a quick check — worth giving them the same clean-split treatment when you have a moment.)

@VasiliyRad VasiliyRad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are correct — every assertion (T1–T15) matches the source behavior in archive-stale-results.py. Good coverage of the key invariants: retention cutoff, dry-run, .txt-only filtering, archive-subdir skipping, naming convention, and the .sending exclusion.

One minor nit (non-blocking): the script always exits 0 regardless of test failures (if __name__ == "__main__": pass with no sys.exit(FAIL > 0)). Other Python tests in the repo (e.g. telegram-bridge-forward-attribution.test.py) exit non-zero on failure so CI catches regressions. Worth a follow-up to add sys.exit(1 if FAIL else 0).

Single file added, no non-test modifications. Clean PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants