Phase 2: Pull-through functional tests¶
Part of PLAN-registry-proxy-future.md.
Planning effort¶
High. The work this phase produces is test code, which sounds
mechanical, but the master plan's specification for it does not run:
it puts a group-level option after a subcommand, assumes an
ephemeral port the proxy cannot report, and assumes test isolation
that stestr --concurrency=5 does not provide. The phase turns on
three design decisions about observability and isolation, not on
typing out five test bodies.
Review effort: the master plan specifies none. High, for the same reason -- a flaky functional test in CI is expensive to diagnose and tends to be silenced rather than fixed.
Scope¶
In scope:
- A second, empty registry on port 5001 in
.github/workflows/functional-tests.yml, to serve as the proxy's downstream cache. - Per-test upstream tags, so no two of these tests share a
downstream
repo:tag(Decision 3). deploy/occystrap_ci/tests/test_pull_through.pywith the_start_proxy/_stop_proxyharness and the master plan's five tests, corrected per the decisions below.- Documentation of the second registry and how to run these tests.
Explicitly out of scope:
- Any change to
occystrap/production code. This phase tests what phase 1 shipped. Two temptations are declined with reasons in Decisions 1 and 2. - A
/statsor/healthzendpoint on the proxy. See Decision 2; it is recorded as future work rather than built here. deploy/ansible/ci.yml. It starts its own registry (deploy/ansible/ci.yml:163-164) and the GitHub workflow does not use it. See Decision 5.- Acting on issue #206, the conductor's recommendation to
downsize the
functionalrunner. See Decision 6. - Multi-architecture pull-through. Unchanged, still owned by
PLAN-compatibility.mdPriority 3. - The push path. These are pull-through tests, and the master
plan's item 3 is pull-through only. Note that the proxy's push
path has no functional coverage either -- nothing under
deploy/occystrap_ci/mentions the proxy at all, andtest_registry_push.pytests theregistry://output writer rather than the proxy. Adding push coverage would be a sensible next step, but it is not in this plan's scope and is not smuggled in here; it belongs in the master plan's future work if anyone wants it.
What the survey found¶
A survey sub-agent verified every factual claim in the master plan's
3. Functional Tests section (lines 193-253) and its two phase-2
rows in Files Modified against develop at b91b43e. Every
finding below was then re-checked in the management session against
the file and line given, because three of them invalidate test code
the master plan states verbatim.
The section is substantially wrong. Five findings are load-bearing.
1. --insecure is not a proxy option, and the master plan puts
it in a position Click rejects. It is a group-level option on
cli (occystrap/main.py:108-109), so it must precede the
subcommand. The master plan writes
occystrap process registry://... tar://temp.tar --insecure
(section lines 224-225) and
occystrap info --insecure registry://localhost:5001/...
(line 233). The first fails with "no such option"; the second
happens to be correct only by accident of where the flag landed.
The correct form is occystrap --insecure process ..., which is
what every existing functional test already does
(deploy/occystrap_ci/tests/test_check.py:31-37). One flag covers
both upstream and downstream: the proxy reads it from
ctx.obj['INSECURE'] at occystrap/proxy.py:924, 963, 992 and
1003, and there is no per-registry scheme selection.
2. The proxy cannot tell a test which ephemeral port it got.
The master plan says "ephemeral port via --listen" (line 217).
--listen is host:port with a default of 127.0.0.1:5050
(occystrap/main.py:1093), port 0 does parse
(occystrap/main.py:1160-1168) and the server does bind to it
(occystrap/proxy.py:1362-1364) -- but the resulting port exists
only inside a human-readable log line,
LOG.info('Proxy registry listening on %s:%d', ...)
(occystrap/proxy.py:1367-1369). There is no port file, no
machine-readable output and no API. See Decision 1.
3. test_cache_hit_on_second_pull as specified asserts nothing.
Its steps are "pull, pull again, both succeed" (section lines
243-247). Both pulls succeed whether or not a cache exists, so the
test passes on a proxy with caching entirely broken. The only
external window onto hit, miss and stale counts is the shutdown
summary at occystrap/proxy.py:1436-1447, printed on SIGTERM only.
See Decision 2.
4. The five tests cannot share one downstream registry under
--concurrency=5. CI runs
sudo .../stestr run --concurrency=5
(.github/workflows/functional-tests.yml:206), and stestr
partitions by test id, so tests in one class can run in different
worker processes simultaneously. All five tests as specified pull
library/busybox:latest, and so all five write the same
downstream repo:tag. test_pull_through_with_filter writes
filtered content to that tag, which changes the layer digests the
unfiltered tests expect, and test_cache_hit_on_second_pull's
counters depend on being the only client of its tag. The master
plan does not mention isolation at all. See Decision 3.
5. A fresh proxy process treats every tag as stale, so a cache hit
can only be observed within one process. Phase 1's Decision 2
makes an absent freshness record mean stale
(occystrap/proxy_freshness.py), and the record is in memory. This
is correct behaviour, but it closes off the obvious way to write
the cache-hit test -- populate downstream in one proxy run, then
start a second proxy with a dead upstream and show the pull still
works. That second pull re-fetches and fails. The hit and the miss
have to happen in one proxy lifetime.
Findings that are smaller but still change the work:
6. The CI registry step is inline, not a tools/ script. The
existing step is roughly twenty lines of inline run: |
(.github/workflows/functional-tests.yml:176-195), which is
already against this repository's own convention that scripts over
about five lines live in tools/. The master plan's one-line
docker run for the second registry is correct as a command shape,
including the mirror.gcr.io/registry:2 image and the
--restart=always flag, and is fine inline. The per-test tag
pushes Decision 3 requires are not, so they go in a new
tools/ script rather than growing the inline step.
7. Nothing in deploy/ starts a subprocess today. There is no
Popen anywhere under deploy/occystrap_ci/tests/, and no existing
helper starts occystrap proxy. So _start_proxy and _stop_proxy
are genuinely new, as the master plan assumes. The unit-test helper
_start_test_proxy (occystrap/tests/test_proxy.py:30-41) is not a
model to copy: it runs the handler in-process on an ephemeral port
and never launches the CLI. An in-process variant is not available
here either, because run_proxy installs signal handlers
(occystrap/proxy.py:1387-1396) and signal.signal only works on
the main thread.
8. The proxy's stdout will block-buffer in a pipe. Console
logging goes through print()
(shakenfist_utilities/logs.py:398-400 in the installed package),
which is block-buffered when stdout is not a terminal. A harness
that waits for the "listening" line without setting
PYTHONUNBUFFERED=1 in the child environment will hang. This is
the single most likely way to produce a harness that works
interactively and times out in CI.
9. GET /v2/ is a sound readiness probe, but the log line is
not. /v2/ returns 200 with {} and the
Docker-Distribution-API-Version header
(occystrap/proxy.py:426-440). The listening log line is emitted
before serve_forever starts (occystrap/proxy.py:1367 versus
1398-1401), so it proves the port is known, not that the server
answers. Both are needed: the line for the port, the probe for
readiness.
10. SIGTERM's graceful path can wait up to 300 seconds.
run_proxy waits for in-flight images before printing the stats
line (occystrap/proxy.py:1415-1431). For an idle proxy this
returns immediately, but the master plan's "waits up to 10s, kills
if needed" (section line 210) would, under load, kill the process
before the stats line that Decision 2 depends on.
11. deploy/requirements.txt has no HTTP client. It is
oslo.concurrency, testtools<2.9.3 and stestr==4.2.1 only. See
Decision 7.
12. The size ratchet and log-level checks do not constrain this
phase, but two files are close to the line.
tools/source-size-ratchet.py:90 sets the threshold at 1500 lines
over every tracked .py and .sh file, so a new deploy/ test
file is covered but will not approach it.
tools/source-size-baseline has exactly one entry,
2087 occystrap/tests/test_proxy.py, and nothing this phase touches
is listed. occystrap/proxy.py is at 1459 lines and
occystrap/main.py at 1485, so either would cross 1500 with about
forty lines added -- a further reason Decisions 1 and 2 keep
production code untouched. tools/check-log-levels.sh scans only
non-test files under occystrap/, so deploy/ is unconstrained.
Corrections made at source. Findings 1, 2, 3, 4, 6, 10 and 11
contradict the master plan's 3. Functional Tests section, so that
section and the master plan's index.md row have been corrected in
the same commit as this plan, with each correction saying what it
previously claimed. A later step should not redo them.
Decisions¶
1. The harness learns the port by parsing the proxy's stdout, not by choosing one.
Two alternatives were rejected. Picking a free port in the test by
binding to 0, closing, and passing the number is racy, and under
--concurrency=5 the race is real rather than theoretical: five
workers choosing ports at the same moment is exactly the case the
pattern loses. Adding a --port-file option, or a machine-readable
line, to occystrap proxy would be the clean engineering answer and
is tempting -- but it changes production code so that tests are
easier to write, in a phase whose whole purpose is to test what
already shipped, and occystrap/main.py has about forty lines of
headroom against the 1500-line ratchet. The log line already exists
and already contains the port.
So _start_proxy runs occystrap --insecure proxy --listen
127.0.0.1:0 ... with PYTHONUNBUFFERED=1 in the child
environment (finding 8), reads stdout line by line until
r'Proxy registry listening on (\S+):(\d+)' matches, then polls
GET /v2/ until it answers 200 (finding 9). Both, not either: the
regex gives the port and the probe gives readiness.
The cost is honest and should be stated: this couples the test suite to a log message's wording. That is the price of the counters and the port having no other interface, and Decision 2 records the way out.
2. Cache behaviour is asserted from the shutdown stats line, and the test owns the whole proxy lifetime.
The master plan's cache-hit test asserts nothing (finding 3), and
finding 5 rules out the cross-process version. So
test_cache_hit_on_second_pull starts its own proxy, pulls its tag
twice, stops the proxy, and asserts on the parsed summary:
one image pulled, one miss, one hit, zero stale. _stop_proxy
therefore has to return those numbers, which means it must drain
stdout after SIGTERM and parse
occystrap/proxy.py:1436-1447.
This is the decision most likely to be argued with. Asserting on a
human-readable log line is the kind of thing that breaks when
someone rewords a message, and the honest alternative is a real
interface -- a /stats endpoint on the proxy returning JSON, which
anyone operating the proxy would also want, and which would make
this test and every future one clean. I am not building it here:
it is production scope in a testing phase, it needs a decision
about exposing internals on the registry port, and proxy.py has
roughly forty lines of headroom. It is recorded as future work in
the master plan instead. Until it exists, the stats line is the
proxy's only account of its own cache, and a test that reads it is
better than a test that asserts nothing.
3. Every test gets its own upstream tag.
Finding 4 means the five tests cannot share library/busybox:latest.
The isolation lever available is the repository and tag in the
request path, because the proxy pushes downstream under the name the
client asked for. So a new tools/push-pull-through-tags.sh retags
the already-pulled busybox under one tag per test and pushes them to
upstream; the layers are already present, so each push is almost
free.
The uniform rule -- one tag per test, no exceptions -- is
deliberate over the cleverer "work out which pairs actually
conflict". Only two of the five strictly need their own tag today,
but that analysis has to be redone correctly every time someone
adds a test, and the cost of the rule is five docker tag
invocations.
The coupling this creates is that the tag list exists in both the script and the test module. The script is the source of truth, the test module names the same tags in one module-level tuple, and a done-criterion greps both and compares.
4. --insecure goes before the subcommand, everywhere.
Finding 1. Both the CliRunner invocations and the occystrap
proxy subprocess use the group-level position, matching
deploy/occystrap_ci/tests/test_check.py:31-37. The per-URI
?insecure=true form exists (occystrap/uri.py:21) but is not used
here, because the existing suite does not use it and consistency is
worth more than brevity.
5. deploy/ansible/ci.yml is left alone, and asked about.
It starts its own registry (deploy/ansible/ci.yml:163-164) and
would drift the moment the workflow gains a second one. It also
synchronises from /home/jenkins/src/occystrap/
(deploy/ansible/ci.yml:178), which is a Jenkins-era path, and the
GitHub workflow never references it. Silently updating a file that
may be dead is worse than leaving it: it implies someone checked.
This phase files an issue asking whether deploy/ansible/ is still
live and should be removed, and changes nothing there.
6. The runner stays at m, and issue #206 waits.
Issue #206 is the CI conductor recommending the functional job be
downsized from m to s -- 2 vCPU and 4 GB -- on sixteen runs
measured before this phase existed. Phase 2 adds a second registry
container and five more tests to a suite already running at
--concurrency=5, and the workflow's own comment
(.github/workflows/functional-tests.yml:87-93) records that the
job was sized up precisely because five concurrent workers
extracting layers exhausted a smaller runner. This phase must not
touch runs-on, and #206 should not be acted on until the conductor
has re-measured after phase 2 lands. A comment on #206 saying so is
part of step 1, so that whoever next sees the issue knows why it is
being left.
7. The blob test uses stdlib urllib.request.
Finding 11: there is no HTTP client in deploy/requirements.txt.
httpx is importable transitively because the venv has occystrap
installed, but test_pull_through_blob_get is checking that the
proxy answers a plain registry client, so a plain client is the
right instrument and urllib.request adds no dependency.
8. _stop_proxy waits 60 seconds and a kill is a test failure.
Finding 10. SIGTERM, then read stdout to EOF while waiting up to 60 seconds for exit. If it has to SIGKILL, the test fails with the captured output rather than passing with absent counters -- a harness that silently loses the numbers Decision 2 asserts on is the failure mode worth paying a timeout to avoid. 60 rather than the master plan's 10 because the graceful path is allowed 300 seconds for in-flight images; these tests pull one small image at a time, so 60 is generous for the idle case without inviting a two-minute hang.
9. The implementer verifies locally, against real registries.
These tests need Docker and two registries, which this host has --
registry:2 is already in the local image cache. So the step
briefs require starting the pair locally, populating them, and
running the new tests to green before the step is reported done,
rather than pushing and letting CI find out. A functional test
nobody has run is a liability.
Step plan¶
| Step | Effort | Model | Isolation | Brief for sub-agent |
|---|---|---|---|---|
| 1 | medium | sonnet | none | CI plumbing, no test code. (a) In .github/workflows/functional-tests.yml, in the step named "Run a local docker registry to talk to, and populate it with test data" (line 176, body 177-195), add one line immediately after the existing docker run at line 178: docker run -d -p 5001:5000 --restart=always --name registry-downstream mirror.gcr.io/registry:2. Use that exact image and those exact flags, matching the existing registry. It needs no population -- it is the proxy's downstream cache and must start empty. (b) Write tools/push-pull-through-tags.sh: #!/bin/bash with set -e, taking the upstream host as $1 and defaulting to localhost:5000, which for each of the five tags pt-serves, pt-populates, pt-filter, pt-blob, pt-cachehit runs docker tag <host>/library/busybox:latest <host>/library/busybox:<tag> and docker push <host>/library/busybox:<tag>. It assumes library/busybox:latest has already been pushed by the loop at workflow lines 192-195, so call it from the workflow after that loop, as a single line: tools/push-pull-through-tags.sh localhost:5000. A top-of-file comment must say that the tag list is mirrored in deploy/occystrap_ci/tests/test_pull_through.py and that the two must agree. chmod +x it. Note shellcheck runs via pre-commit on ^(tools/|release\.sh) with -x, so it must be shellcheck-clean. (c) Do not change runs-on (line 94) and do not add a job -- a new job would have to join the needs: of "Can enqueue" and "Can merge" per AGENTS.md, and this adds neither. (d) Post a comment on GitHub issue #206 saying the functional job is about to gain a second registry container and five more tests, so its size recommendation should be re-measured after this phase lands rather than acted on now; do not close it. Commit subject: Add a downstream CI registry for pull-through tests. |
| 2 | high | opus | none | Write the harness and the first test in a new deploy/occystrap_ci/tests/test_pull_through.py. Read deploy/occystrap_ci/tests/test_check.py:1-45 first for the house style: module docstring naming the registry prerequisite, testtools.TestCase, CliRunner, logging.basicConfig. Module-level PULL_THROUGH_TAGS = ('pt-serves', 'pt-populates', 'pt-filter', 'pt-blob', 'pt-cachehit'), mirroring tools/push-pull-through-tags.sh from step 1, with a comment saying so. UPSTREAM = 'localhost:5000', DOWNSTREAM = 'localhost:5001'. _start_proxy(downstream, upstream=None, filters=(), check_interval=None): builds [sys.executable, '-m', 'occystrap.main', '--insecure', 'proxy', '--listen', '127.0.0.1:0', '-d', downstream] plus -u upstream, -f per filter and --upstream-check-interval when given -- note --insecure is a group-level option and must come before proxy (occystrap/main.py:108-109); putting it after fails. Check whether python -m occystrap.main works, and fall back to the occystrap console script (pyproject.toml:46) if not. Launch with subprocess.Popen(..., stdout=PIPE, stderr=STDOUT, text=True, env={**os.environ, 'PYTHONUNBUFFERED': '1'}) -- the PYTHONUNBUFFERED is not optional: console logging is print() (installed shakenfist_utilities/logs.py:398-400) and block-buffers into a pipe, so without it the next step hangs forever. Start a daemon thread that reads stdout line by line into a list, so the pipe never fills and blocks the child. Wait up to 30s for a line matching r'Proxy registry listening on (\S+):(\d+)' (occystrap/proxy.py:1367-1369); the formatter puts a timestamp, the level and an ANSI reset before the message, so search the line rather than anchoring it. Then poll GET http://127.0.0.1:<port>/v2/ with urllib.request until it answers 200 (occystrap/proxy.py:426-440) for up to 30s -- the log line is printed before serve_forever starts (occystrap/proxy.py:1367 versus 1398-1401), so the line alone does not mean ready. On either timeout, kill the child and fail with the captured output. Return an object carrying the port, the process and the captured lines. _stop_proxy(proxy): SIGTERM, proc.wait(timeout=60), then join the reader thread; on TimeoutExpired, SIGKILL and raise, failing the test with the captured output -- see Decision 8, the graceful path is allowed 300s for in-flight images (occystrap/proxy.py:1415-1431) so a kill means something is wrong, not merely slow. Then parse the shutdown summary occystrap/proxy.py:1436-1447 ("Proxy stopped. Pushed %d images (%d failed). Pulled %d images (%d cache hits, %d misses, %d stale re-fetches).") into a dict with keys pushed, push_failed, pulled, hits, misses, stale, and return it; raise if the line is absent. One regex, defined once at module level. Then write test_pull_through_serves_image only: start a proxy with --upstream localhost:5000 -d localhost:5001, CliRunner().invoke(cli, ['--insecure', 'process', 'registry://127.0.0.1:%d/library/busybox:pt-serves' % port, 'tar://%s' % path]) into a tempfile.TemporaryDirectory(), assert exit 0, then CliRunner().invoke(cli, ['--insecure', 'check', 'tar://%s' % path]) and assert exit 0 (occystrap/main.py:1013-1020, exit 1 on errors). Stop the proxy and assert pulled == 1 and misses == 1. Verify locally before reporting done (Decision 9): docker run -d -p 5000:5000 --name registry registry:2 and -p 5001:5000 --name registry-downstream, push busybox and the pt-* tags with step 1's script, then cd deploy && stestr run test_pull_through. Clean the containers up afterwards. Single quotes, double-quoted docstrings, 120 columns. Commit subject: Add a pull-through functional test harness. |
| 3 | medium | sonnet | none | Add the remaining four tests to deploy/occystrap_ci/tests/test_pull_through.py, reusing step 2's helpers unchanged. Each uses its own tag from PULL_THROUGH_TAGS and starts its own proxy, because stestr --concurrency=5 (.github/workflows/functional-tests.yml:206) partitions by test id and may run these simultaneously in separate processes -- sharing a downstream repo:tag across tests is the flakiness this layout exists to prevent. (a) test_pull_through_populates_downstream, tag pt-populates: pull through the proxy to a tarball, stop the proxy, then CliRunner().invoke(cli, ['--insecure', 'info', 'registry://localhost:5001/library/busybox:pt-populates']) and assert exit 0 -- that is the assertion that the downstream cache was actually written. (b) test_pull_through_with_filter, tag pt-filter: start the proxy with filters=('normalize-timestamps',) (valid per occystrap/main.py:1143-1146), pull to a tarball, assert occystrap --insecure check tar://... exits 0. (c) test_pull_through_blob_get, tag pt-blob: with urllib.request and not httpx or requests (deploy/requirements.txt has no HTTP client), GET http://127.0.0.1:<port>/v2/library/busybox/manifests/pt-blob sending Accept: application/vnd.docker.distribution.manifest.v2+json, assert 200, json.loads the body, take layers[0]['digest'], then GET /v2/library/busybox/blobs/<digest> and assert 200 and a non-empty body. (d) test_cache_hit_on_second_pull, tag pt-cachehit: one proxy, two sequential pulls of the same tag to two different tarball paths, both exit 0; stop the proxy and assert the parsed summary is pulled == 2, misses == 1, hits == 1, stale == 0. That last assertion is the point of the test -- the master plan's version asserted only that both pulls succeeded, which passes with caching entirely broken. The default --upstream-check-interval of 0 is correct here and must not be overridden: the second request does HEAD upstream, finds the recorded digest unchanged and serves the cache, which is a genuine hit. Verify locally against two real registries before reporting done, as in step 2, and clean up the containers. Commit subject: Add pull-through functional tests for the proxy. |
| 4 | medium | sonnet | none | Documentation, and the issue from Decision 5. (a) docs/development.md:99-101 currently says functional tests run "against a local registry at localhost:5000 that the workflow populates with test images". Correct it to describe both registries: the populated upstream on 5000 and the empty downstream cache on 5001 that the pull-through tests use, and mention tools/push-pull-through-tags.sh and the one-tag-per-test rule so the next person adding a pull-through test knows to add a tag rather than reuse one. (b) In the same file's "Running tests" area, say how to run these locally: two docker run registry containers, the tag script, then cd deploy && stestr run test_pull_through. (c) docs/command-reference.md needs no change -- no CLI surface changed this phase; confirm that and say so rather than editing it. (d) Per this repository's documentation policy, README.md and ARCHITECTURE.md should not change: no new component, no new pitch, no new convention. AGENTS.md is a judgement call -- its Testing section (lines 133-134) says functional tests are "Run in CI", and the fact that they can now be run locally against two registries is arguably a convention an agent cannot infer; add at most one line pointing at docs/development.md, and if you judge it unwarranted, say why instead. (e) File a GitHub issue asking whether deploy/ansible/ is still live: it starts its own registry (deploy/ansible/ci.yml:163-164), synchronises from the Jenkins-era path /home/jenkins/src/occystrap/ (line 178), is referenced by no workflow, and will now be inconsistent with CI's two registries. The issue should ask whether to update or delete it, not assert which. Commit subject: Document the two CI registries for pull-through tests. |
Risks and mitigations¶
| Risk | Mitigation |
|---|---|
| The harness hangs in CI waiting for a "listening" line stuck in a pipe buffer, and the job burns its 120-minute timeout. This is the most likely single failure of this phase. | PYTHONUNBUFFERED=1 is named in step 2's brief as not optional, with the reason. Every wait in the harness is bounded (30s for the line, 30s for readiness, 60s for exit) and fails with captured output rather than blocking. The management session reads the Popen call and the three timeouts in the diff rather than trusting the report. |
Two of these tests race on a shared downstream tag under --concurrency=5 and the suite becomes intermittently red, which historically gets silenced rather than fixed. |
Decision 3's one-tag-per-test rule, enforced by a done-criterion that greps the script and the test module and compares the lists. The management session also checks that each test starts its own proxy rather than sharing a fixture. |
test_cache_hit_on_second_pull asserts on a log message, so rewording occystrap/proxy.py:1436-1447 silently breaks it -- or worse, the regex quietly fails to match and the test reports absent counters as a pass. |
_stop_proxy raises when the summary line is absent, rather than returning zeros; that is explicit in step 2's brief and is a done-criterion. The deeper fix is the /stats endpoint recorded as future work. |
| The implementer writes five plausible tests that pass against a broken proxy, which is exactly what the master plan's specification would have produced. | The done criteria require two inversions: breaking the cache-hit path must fail test_cache_hit_on_second_pull, and breaking the downstream push must fail test_pull_through_populates_downstream. Steps 2 and 3 also require a local run against real registries before being reported done (Decision 9), so the first time these tests run is not in CI. |
| Phase 2 lands, and #206 is then actioned on stale measurements, downsizing the runner into the failure its own comment describes. | Step 1 comments on #206 explaining the timing. The workflow's existing comment at lines 87-93 already records why it is m; this phase does not touch runs-on. |
The new tools/push-pull-through-tags.sh fails shellcheck in pre-commit, since ^(tools/|release\.sh) is in scope. |
Named in step 1's brief. pre-commit run --all-files catches it before the commit either way. |
Definition of done¶
Falsifiable items:
-
pre-commit run --all-filespasses, includingshellcheckon the newtools/script,source-size-ratchet,check-log-levels,tox -eflake8andtox -epy3. - Revised during implementation. This item originally
required
git diff develop --statto show no file underoccystrap/changed, on the reasoning that this phase adds tests and CI plumbing only and a production change would mean a decision had been quietly reversed. The first run of the new functional tests then found that_proxy_downstream_responseiterated an httpx response with therequestsAPI, so every serve from the downstream cache failed and the client got a truncated body. The phase cannot pass its own tests without that fix, so the criterion was put to the operator rather than worked around, and the revised requirement is that the only production change is that one call and the tests that cover it. Verify withgit diff develop --stat -- occystrap/listing exactlyproxy.py,tests/test_proxy.py,tests/test_proxy_freshness.pyandtests/test_proxy_streaming.py, andgit diff develop -- occystrap/proxy.pybeing a one-line change. Recorded as issue #217. - Revised during review round 2. This item originally
required
tools/source-size-baselineto be unmodified andwc -l occystrap/proxy.py occystrap/main.pyto report fewer than 1500 lines each, on the reasoning that a phase of tests should not grow production source at all. It held until the round 2fixitem, which is inoccystrap/proxy.py: the change and the rationale around it took the file from 1471 to 1520 lines, across the ratchet's 1500-line threshold, so an entry had to be added by hand. The ratchet's own message says deleting comments to get under a threshold is not a fix, and splitting a 1500-line request handler is not review-round work. The revised requirement is that the baseline gains exactly one entry,1520 occystrap/proxy.py, thatoccystrap/main.pyis still under the threshold, and that the pull request says why the file grew rather than split. -
docker run -d -p 5001:5000 --name registry-downstreamappears in.github/workflows/functional-tests.yml, andgrep -c 'runs-on' .github/workflows/functional-tests.ymlis unchanged withvm, debian-13, mstill on line 94. - Revised during review round 2. The tag lists agree, and
this is no longer checked by hand. The original item was a
diffof twogrep -o "pt-[a-z]*"runs, which nothing executed; round 2 raised that.TagListTestCaseindeploy/occystrap_ci/tests/test_pull_through.pynow reads the script'sfor tag in ...loop and asserts it equalsPULL_THROUGH_TAGS, so the revised requirement is that the test exists and that adding a tag to either side alone fails it. - Each of the five tests uses a distinct tag, and no two use the
same one. The
diffabove plus five tests means a bijection; confirm by reading. - Every
CliRunnerinvocation and the proxy subprocess put--insecurebefore the subcommand. Verify withgrep -n "insecure" deploy/occystrap_ci/tests/test_pull_through.pyand reading each hit -- no occurrence follows'process','check','info'or'proxy'in an argument list. -
PYTHONUNBUFFEREDappears in the_start_proxyenvironment. -
_stop_proxyraises rather than returning when the shutdown summary line is not found. Verify by pointing its regex at a string that cannot match and confirming a test errors. - The five tests pass against two real registries on this host:
cd deploy && stestr run test_pull_throughreports 5 passing (6 from review round 2, which addedTagListTestCase, the one test in the module that needs no registry), with registries on 5000 (populated, including thept-*tags) and 5001 (started empty). Run it withPYTHONPATH=$(git rev-parse --show-toplevel):stestrruns fromdeploy/, so without it the suite imports whicheveroccystrapis installed, which on a machine with several worktrees and an editable install is another tree entirely. Round 2 hit exactly that and watched the suite report the already-fixediter_contentbug from the primary clone. - Inversion: forcing the freshness verdict to miss in
occystrap/proxy.pymakestest_cache_hit_on_second_pullfail, and no other test in the new module fails. Restore the file afterwards. - Inversion: making the downstream push a no-op makes
test_pull_through_populates_downstreamfail. Run against a mutated copy, never the checkout. Note the limit found in doing so: it fails at the pull with a 502 rather than at its own downstream assertion, because the proxy serves a pull by reading back what it wrote, so the write cannot be broken in isolation and the test cannot distinguish a write that never happened from one it could not read back. The assertion is still the right one. -
docs/development.mddescribes both registries, and no fact about which port is populated is stated differently there and in the workflow. - An issue exists asking whether
deploy/ansible/is live, and a comment exists on #206 explaining why it is being left. -
README.mdandARCHITECTURE.mdare unchanged.
The two inversions are the load-bearing items. The specific failure
this phase is exposed to is five tests that pass whether or not
pull-through caching works -- which is what the master plan's
specification would have produced, since four of its five tests
assert only that a command exited 0. Consider the mutation-check
skill over steps 2 and 3 rather than relying on the inversions
alone.
Back brief¶
Before executing any step, back brief the operator on the understanding of this plan and how the intended work aligns with it.
Gate before step 2. Step 1 is CI plumbing and cheap to redo.
Step 2 fixes the shape of the harness -- how the port is learned,
what _stop_proxy returns, and whether the counters are parsed at
all -- and steps 3 and 4 are built on it, so it is cheap to propose
and expensive to redo. Agree the harness's interface with the
operator before writing it: specifically the return value of
_start_proxy and _stop_proxy, and whether Decision 2's stats
parsing stands or the /stats endpoint should be pulled into scope
after all.
Execution notes¶
Implemented 2026-12-03 and 2026-12-04 (AEDT), one sub-agent per
step, run sequentially: every step writes to the same worktree and
most run tox or pre-commit, which cannot overlap in one tree.
Each step was reviewed in the management session against its diff
rather than its report, and committed there.
Back brief answers. Decision 2 stands: the cache counters are
parsed from the proxy's shutdown summary and no /stats endpoint
was built. The harness interface is as the plan proposed --
_start_proxy returns an object carrying the port, the process and
the captured output, and _stop_proxy returns the parsed counters
and raises when the summary line is missing. The sub-agents were
given permission to write to GitHub. This session was given
permission to push and open the pull request once the definition of
done passed.
The phase found a production bug on its first real run, and
fixing it was pulled into scope. _proxy_downstream_response
iterated the downstream response with iter_content(), the
requests API, on what util.request_url() returns as an httpx
response. Every serve from the downstream cache therefore raised
AttributeError after the headers had gone out, and the client got
a truncated body; pull-through only appeared to work when it went
to upstream instead. Broken by db9e826 (2026-03-24), which
rewrote occystrap/util.py and did not touch occystrap/proxy.py,
and invisible for eight months because every unit test covering
those paths mocked iter_content and a MagicMock answers any
attribute asked of it.
This phase had scoped occystrap/ changes out, so the decision was
put to Michael rather than taken here; he chose to fix it in this
phase rather than in a separate pull request, with a regression
test a mock cannot satisfy. The fix is one word, the six mocks that
hid it are renamed, and occystrap/tests/test_proxy_streaming.py
covers it with real httpx responses and an autospec of
httpx.Response, which raises for any method httpx does not
define. Reverting the fix in a copy of the tree makes three of its
four tests fail. Recorded as issue #217. The definition of done's
"no file under occystrap/ changed" item is revised accordingly;
it was the right default and the wrong answer once the tests did
their job.
Two smaller departures.
The registry host constants read the environment
(OCCYSTRAP_CI_UPSTREAM, OCCYSTRAP_CI_DOWNSTREAM), defaulting to
the CI ports. Decision 9 requires the tests to be run locally
before being reported done, and on the development host port 5000
is permanently held by an unrelated project's registry. The
defaults mean CI is unaffected and the workflow needed no change.
The cache counters are asserted as invariants rather than exact
paths. The plan had the first test assert misses == 1 and the
cache test assert stale == 0. A stale re-fetch increments
misses as well as stale, and a freshly started proxy treats a
tag the downstream already holds as stale, so stale depends on
whether the downstream started empty. The tests assert misses
and hits and leave stale alone, which holds either way. The
management session first proposed misses + stale == 1 here and
was wrong; the step 2 sub-agent measured the counters and corrected
it.
Requests to the proxy go through a urllib opener with proxy
handling disabled. Every one is to loopback, and an inherited
http_proxy would send it somewhere that cannot answer. The unit
suite has its own helper for the same reason, which the first draft
of the harness had not matched; found in review.
Review round 1. The automated reviewer raised one fix item and
it was a real one: _proxy_downstream_response iterated the
response but never closed it, and the blob path hands it a
streaming response, which holds a connection out of the
per-thread httpx pool until closed. The AttributeError had made
that leak unreachable, so the one-word fix uncovered it. The copy
now closes in a finally, which is a no-op for the manifest
path's already-read response, and three unit mutants (the close
removed, the close moved out of the finally, iter_bytes
reverted) each fail the test named for them. So the production
change is no longer one word; it is one word and a finally.
Two further departures from this plan came out of the same round.
_start_proxy loses the check_interval parameter the step table
specified: no test passes it, the stale re-fetch it exists for is
scoped out of this phase, and untested argv construction is worth
less than nothing. Re-add it with the test that uses it. And the
harness now sets a loopback no_proxy for the proxy subprocess and
for the in-process pulls, which build their httpx client from the
environment -- the urllib opener above covered only the harness's
own requests. With http_proxy set to a dead address all five
tests pass; with the no_proxy removed from a copy of the tree, all
five fail.
Review round 2. One fix item, also real, and also something
the round 1 fix had made reachable rather than something new:
_handle_pull_blob guarded the fetch and the streaming copy with
one except Exception: send_response(404), so a failure part way
through a blob appended a second status line to bytes the client was
reading as blob content. Before the iter_bytes fix every request
failed on its first line of iteration, so this path was never
reached with a body already sent.
It is fixed in _proxy_downstream_response rather than in the
handler the review named. The reviewer suggested narrowing the
caller's try, which fixes the one caller; putting the handling
where "the headers have already gone out" is known means no caller
can answer a half-sent response, and it gives the manifest path --
which guarded nothing and would have raised into a socketserver
traceback -- the same logged, connection-closing behaviour. Both
callers' guards are narrowed to the fetch as well, so the code reads
the way it behaves. That narrowing is not separately testable once
the copy absorbs its own failures, and no test here claims it is.
Sweeping the class found a second instance the review had not:
_handle_head_blob had the same shape, with send_response(200)
and its headers inside the broad try. There is no body on that
path, but the status line and the headers share one buffer which
end_headers() flushes, so a 404 sent from among them arrives as a
second status line too. Both were narrowed together.
Eight mutants, each killed by a named test, with a control run on an
unmutated copy first -- which earned its place immediately: the
first run of the mutation script used python3 rather than the
virtualenv's python, so every test failed on an ImportError and
every mutation was reported as killed. The eighth mutant restores
the reported defect exactly rather than approximating it, and that
in turn found that the test's status-line scan missed the second
status line, because it is written straight onto the end of a body
with no CRLF in front of it -- which is precisely what makes a
client read it as content. The scan now searches the bytes rather
than splitting them into lines.
The round also took five consider items, all of them consistency
windows this phase itself opened: the mirrored tag list is now a
test rather than a diff in this file, the readiness poll notices a
proxy that exited, both reader-thread joins report a timeout as
their own failure, the fixture script checks its one precondition
under set -euo pipefail, and docs/development.md no longer says
the downstream must start empty when the tests were deliberately
written not to need it -- verified by running the suite twice
against a downstream the first run populated.