Skip to content

fix(#815): disclose a malformed TRUSTED config layer, matching #804's untrusted-layer disclosure - #818

Merged
fdaviddpt merged 4 commits into
mainfrom
fix/815
Sep 27, 2026
Merged

fdaviddpt merged 4 commits into
mainfrom
fix/815

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

lib-memory-dir.sh's no-jq Python-fallback config merge loaded every TRUSTED config source (bundled config, user-global config, or project config when it is not the untrusted-haiku source) with no error handling. A malformed file there raised an uncaught JSONDecodeError, the subprocess exited nonzero-but-not-3, and the shell's bundled-only fallback fired with zero disclosure, since #804's disclosure gate only checks the drop-marker file or rc == 3, both reserved for the sibling untrusted-project-layer case.

This closes the exact gap #804's own self-review flagged as a trap.d fragment and #815 was filed from.

Design decision

Gave the malformed-trusted-layer case the same disclosure treatment #804 already gives the untrusted layer, rather than declaring it out of scope (the issue's own "What would settle it" section left this open). Reasoning: more consistent with the shipped sibling case, favoured by the issue's own framing, and cheaper than writing an explicit out-of-scope boundary comment. Flagging this as a real judgment call in case the maintainer would have preferred "operator error, out of scope" instead.

What changed

Self-review

Two rounds, each with Explore and oss:auditor spawned in parallel. Round 1 (over the initial fix): both reviewers independently found the new WARNING text named only two of the three trusted sources, and Explore additionally found the positive test's main assertion didn't actually discriminate fixed-vs-broken behaviour -- both fixed, and the test fix was mechanically verified against the true pre-#815 baseline (red, then green). Round 2 (triggered by a >=3-file second-pass check): both reviewers independently found a class-level docstring left stale by round 1's own fix -- fixed. Tree snapshot clean throughout.

Tests

Targeted run only (never the full pytest suite, per repo convention):

python3 -m pytest tests/test_untrusted_project_haiku_config_726.py tests/test_case_divergence_298.py -q --no-cov

-> 67 passed.

Cross-platform

Reasoned, not observed: both touched test files carry a pre-existing, unchanged skipif(sys.platform == 'win32', ...) (#79) covering the new material by position, and the diff reuses the existing (OSError, ValueError) exception shape with no new path/encoding/subprocess construct. Not run on Windows or macOS/Linux CI directly.

Closes #815.

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 4 commits September 27, 2026 09:16
…discloses an untrusted one

`lib-memory-dir.sh`'s no-jq Python-fallback merge loaded every TRUSTED config
source (bundled config, user-global config, or the project config when it is
not the untrusted-haiku source) with no error handling. A malformed file
there raised uncaught, exiting the subprocess with a code that is neither 0
nor 3, so the shell's own bundled-only fallback fired silently -- #804's
disclosure gate only checks the drop-marker file or `rc == 3`, neither of
which this path ever touches. A caller saw the identical "fell back to
bundled config" behaviour whether nothing but bundled config ever existed, or
a trusted file the operator actually wrote was corrupt and silently
discarded.

This is the exact gap #804's own self-review logged to trap.d/ and #815 was
filed from. Wraps the trusted-source load in the same fail-CLOSED shape the
untrusted branch already uses (skip just that layer, keep merging the rest),
and adds two new exit codes -- 4 for a trusted-only drop, 5 for both a
trusted and the untrusted layer dropping in the same run -- so the shell can
print a second, distinct WARNING without a second marker file.

Adds a paired positive/negative test (malformed user-global config warns and
drops just that layer; a well-formed one does not warn), and folds a new
`_SANCTIONED_DIVERGENCE` entry for the byte-pin guard in
tests/test_case_divergence_298.py to match.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…hen its test

Both spawned reviewers (Explore and oss:auditor) independently flagged the same
gap: the new rc-4/5 WARNING said only "bundled or user-global config," but the
branch it fires for also covers project config in external-storage mode (when
it is not the untrusted-haiku source) -- an operator on that layout debugging a
malformed project config would be pointed at the wrong two files. Widened the
message to name all three trusted sources the branch actually reaches.

Explore separately found the positive test's merged-value assertion did not
discriminate fixed from pre-fix behaviour: the bundled-config fixture and the
`_bundled_cfg` fallback target were the same file, so a value that survived
under a full wholesale fallback looked identical to one that survived under a
per-layer drop. Added a third, well-formed project-config layer read AFTER the
malformed one in merge order -- confirmed against the true pre-#815 baseline
that this addition alone goes red (asserting `extra_layer` survives) and green
against the fix, which the prior assertion did not.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…view commit

Both second-pass reviewers (Explore and oss:auditor) independently found the
same gap: 8df6cae added a well-formed project-config layer to the first test
in TestMalformedTrustedConfigDisclosure as a fixed-vs-broken discriminator,
but never updated the class's own docstring, which still claimed neither
test holds a project config and both go through the trusted-load branch this
class is about. Traced (as both reviewers did independently): in this file's
default legacy layout, that project layer is the untrusted-haiku source and
is processed by the pre-existing #744 branch, not the #815 trusted-load
branch -- it is there purely as an order-dependent discriminator, which the
in-method docstring already explained correctly. Corrected the class
docstring to match.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ide it

CI on PR #818 caught tests/test_sanctioned_divergence_state_440.py red on
windows-latest 3.10/3.11 -- a pure Python string-substitution bug, not a
platform flake, so it would have reproduced on every leg. My own commit
comments already cited case-divergence-pin-fold-dont-stack.md, but I only
quoted its convention rather than following it: I stacked a third tuple onto
tests/test_case_divergence_298.py's `_SANCTIONED_DIVERGENCE` list whose
old_code duplicated the existing #804 tuple's new_code, instead of folding
the transition into that tuple in place. `_apply_sanctioned_divergence` runs
substitutions in list order and stacking meant the #815 pair rewrote the
#804 pair's own output out from under it once both were live together,
exactly the "old AND new code both vanish" failure the fold-don't-stack doc
describes for #734/#746.

Replaced the separate #804 and #815 tuples with a single folded pair: old_code
is now the #804 steady state (what origin/main ships today, moved here
verbatim per the doc's own worked example), new_code is the full #815 form
including the round-2 self-review's widened warning text. No production code
changed -- scripts/lib-memory-dir.sh is untouched by this commit.

Verified genuinely red on the pre-fold (stacked) shape: temporarily restored
it via `git stash` and ran `pytest tests/test_sanctioned_divergence_state_440.py`,
which failed 3 of 4 with the "neither the old nor the new code ... is on
origin/main" / "new_code not found in result" assertions the reviewer's
report predicted. Restoring the fold: 4/4 pass, and the full targeted set
(this file + test_case_divergence_298.py + test_untrusted_project_haiku_config_726.py)
is 71 passed.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit a0ea35b into main Sep 27, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/815 branch September 27, 2026 08:14
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.

lib-memory-dir.sh: malformed TRUSTED config JSON silently falls back to bundled config, no disclosure

1 participant