Skip to content

Characterize main's unguarded cache and location failures - #56

Merged
dmccoystephenson merged 2 commits into
mainfrom
feature/characterize-unguarded-main-failures
Nov 4, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
feature/characterize-unguarded-main-failures

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle, with the matching README note. main.py already had 100% line coverage, but no test or document described its failure paths outside the two calls already covered (get_environment_by_id, which is guarded, and create_environment, which was characterized in #43). No production code is changed.

New TestUnguardedFailures cases in tests/test_main.py:

  • environments.json that is empty or malformed: JSONDecodeError propagates before Viron is contacted, and the file is left as it was.
  • environments.json holding valid JSON that is not an object ([]): TypeError propagates, but only after create_environment has run, so a new Viron environment goes unrecorded.
  • A cache entry with no environment_id: KeyError propagates, because the lookup sits just above the try, so the Error loading environment path is not taken.
  • get_locations_in_environment failing after a creation, with and without --exit-after-create: the exception propagates, the environment stays recorded, and environment-created has already been reported.
  • get_locations_in_environment failing after a successful load: the exception propagates and no load error is drawn.

README.md gains a short list under the existing failure paragraphs, including how each state is recovered from where a recovery exists.

Nothing here asserts on window.close(). Pygame is left initialised on every one of these paths, the same asymmetry #42 asks about, and that question remains open.

No tracking issue: the gap was found during triage. The related question is recorded as a comment on #42 instead of a new issue, since one decision covers both.

Test plan

  • python3 -m unittest discover -s tests: 165 tests ran, OK (159 before, plus 6 new)
  • python3 -m py_compile on every module listed in the CI workflow passes
  • python3 headless_run.py: all three scenarios PASS with the real Pygame on SDL's dummy drivers
  • Probe with the real Pygame on SDL's dummy drivers, using in-memory Viron services: all seven failure inputs raised the exceptions described above, with pygame.get_init() still True
  • Mutation check: main.py was temporarily changed to tolerate a damaged cache file, to move the environment_id lookup inside the try, and to catch both location fetches. All 6 new tests failed (7 failures counting subtests), and restoring the source returned the suite to green
  • The interactive anchor (python3 main.py 10 --exit-after-create against a live Viron) is UNVERIFIED-not-applicable: no rendering or Viron-service code is touched. The exceptions from real HTTP failures were not observed; the service source was read to confirm raise_for_status() is called on the location fetch

Deferred issues

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

dmccoystephenson and others added 2 commits November 4, 2026 03:19
Line coverage of main.py is already 100%, but no test or doc said what
happens when environments.json is damaged, when an entry has no
environment_id, or when fetching locations fails. All of these propagate
out of main(), and a non-object cache file only fails after Viron has
created an environment. Pin that and describe it in the README. window.close()
is left unasserted, since that is the question open in #42.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every run against such a file creates another unrecorded environment, and
it was the only listed failure without a recovery step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (anchored on CI run 41813543390, which passed at head 8b5bd71, and on a local run of 165 tests, all OK):

  • Scope: PASS. Only tests/test_main.py (+77) and README.md (+7) change. main.py is unchanged at the PR head, which was confirmed after the mutation check was undone.
  • Tests-new: PASS. No public functions were added. Each newly documented failure has a test.
  • Tests-fix: N/A, with a mutation check in its place. No bug is fixed. main.py was temporarily changed to tolerate a damaged cache file, to move the environment_id lookup inside the try, and to catch both location fetches. All 6 new tests then failed, and the suite went green again once the source was restored.
  • Sibling structure: PASS. The new class extends MainTestCase, reuses runMain, writeCacheFile, readCacheFile and setFrames, and follows the test_a_failed_<x>_... naming. It sits directly after the creation-failure characterization it extends.
  • Sibling renames: N/A. Nothing is renamed.
  • Docs: FAIL, then PASS after a fix. The [] bullet at first gave no recovery step, although the other cache bullets did and every further run orphans another Viron environment. This was fixed in 8b5bd71. README.md lines 179 to 183 otherwise match the probe output and the tests. The .bat scripts are unaffected, and the statement that create_environments.bat relies on a non-zero status still holds for these paths.
  • Issue resolution: N/A. There is no Closes reference. A failed environment creation leaves the window open and shows no error, unlike a failed load #42 stays open because its decision is still pending, and the extra paths were recorded there as a comment.
  • Manual validation: PASS for the unit suite, py_compile, headless_run.py and the real-Pygame probe; UNVERIFIED-not-applicable for the interactive Viron run, since no rendering or service-call code is touched.

Inline notes:

The diff is review-ready. No do-not-auto-merge path is touched, and no file has more than 50 lines deleted.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit f3d7225 into main Nov 4, 2026
1 check passed
@dmccoystephenson
dmccoystephenson deleted the feature/characterize-unguarded-main-failures branch November 4, 2026 10:22
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.

1 participant