fix(contract): pin the baseline to the snapshot's platform commit - #253
Merged
Merged
Conversation
Without --sha, refresh_wire_shape_baseline.py fell back to `git rev-parse HEAD` of the specs directory. The spec snapshot now lives inside this repository, so that records the SDK's own commit as openapi_specs_sha, silently. The snapshot script gains snapshot_commit(), which reads the platform commit from every file's generated header and requires them all to name the same full 40-character commit; --check-snapshot enforces that too, and deriving refuses an abbreviated --source-commit. The refresh script takes the commit from there, refuses a --sha that disagrees, and requires --sha only for a directory that is not a generated snapshot. The git fallback is gone. A test pins the headers' commit to the baseline's openapi_specs_sha. Signed-off-by: Saurabh Jain <saurabh.jain@getaxonflow.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #251.
Without
--sha,scripts/refresh_wire_shape_baseline.pyfell back togit rev-parse HEADof the specs directory. The spec snapshot lives inside this repository, so that recorded the SDK's own commit asopenapi_specs_sha, and the script exited 0. Nothing downstream could tell: the pin guard compares the baseline's SHA with the base branch's, and no test compared it with the snapshot.Every snapshot file already names the platform commit it was derived at, in its generated header. The refresh now reads the commit from there.
Changes
scripts/snapshot_openapi_schemas.pysnapshot_commit(dir)reads line 2 of every*.yaml,# Source: docs/api/<file> at platform commit <SHA>, and returns the commit they all name.Nonefor a directory with no generated file, such as a platform checkout'sdocs/api.--check-snapshotenforces the same agreement.--source-commit, so the script cannot write a snapshot its own reader refuses. Every header names a full 40-character commit.scripts/refresh_wire_shape_baseline.pyresolve_specs_shatakes the commit from the snapshot's headers and refuses a--shathat contradicts them.--sha.git rev-parse HEADfallback is deleted.tests/test_snapshot_openapi_schemas.pypins the headers' commit to the baseline'sopenapi_specs_sha. It also covers snapshots whose files name different commits, a header naming another file, an abbreviated commit on both the derive side and the read side, and a plain specs directory.tests/test_refresh_wire_shape_baseline.pycovers the resolution: the snapshot's commit is read, a contradicting--shais refused before anything is written, and a plain directory must name its commit.CONTRIBUTING.mdnow runs the contract and the refresh against the committed snapshot. It had them cloning the mirror and relying on its HEAD.--sha".No SDK code, no
openapi_specs_shaand no snapshot*.yamlchanges, so there is no CHANGELOG entry: this is contract tooling only, as in #249 and #250. It does carry thespec-pin-bumplabel, because the snapshot README lives undertests/fixtures/openapi/and the pin guard treats any change there as a change to the pin. The guard's own log on this PR readsopenapi_specs_sha 36e0e96b7e5c16626d394272b727b533f2b94a04 -> 36e0e96b7e5c16626d394272b727b533f2b94a04; snapshot changed: true: the pin is unchanged, and the only file changed under that directory isREADME.md.The snapshot script is vendored byte-identical into the other SDKs, and each takes this change in its own pull request: TypeScript under getaxonflow/axonflow-sdk-typescript#278, and Go and Java in their spec-pin pull requests.
Testing
python scripts/refresh_wire_shape_baseline.py tests/fixtures/openapiwith no--shaexits 0. It rewritestests/fixtures/wire_shape_baseline.jsonbyte-identical to the committed one, reportingopenapi_specs_sha36e0e96b7e5c16626d394272b727b533f2b94a04, 107 registered models and 22 drift entries.--sha 0000000000000000000000000000000000000000, it exits 2 witherror: --sha 0000000000000000000000000000000000000000 disagrees with tests/fixtures/openapi, whose generated headers name platform commit 36e0e96b7e5c16626d394272b727b533f2b94a04, and the tree is unchanged.snapshot_commitaccepting files that name different commits;snapshot_commitaccepting a header that names another file;--check-snapshotno longer enforcing one commit;--sha;--sha;ruff check .,ruff format --check .,--self-test(now 12 checks) and--check-snapshot tests/fixtures/openapiall pass, each checked on its own exit code.