Repository navigation
tests: unit-test check_cache_drift.py's verdict without clang - #15
Open
ZheFeng7110 wants to merge 2 commits into
Open
ZheFeng7110 wants to merge 2 commits into
ZheFeng7110 wants to merge 2 commits into
Conversation
The nightly cache-drift workflow does not run on pull requests, and no test imported its driver, so a PR could break the verdict (or turn real drift into a "no drift" pass) and merge. tools/tests/test_check_cache_drift.py runs in verify-scripts.yml's `unittest discover` and covers diff_files, affected_libs, unified/write_diff, copy_entries, summarize, and check() with generate/audit/git steps mocked: no drift, A != B, audit A != B, B != C, all at once, and no GITHUB_OUTPUT. It asserts the exit code, status.json and the cache_drift/committed_drift outputs the workflow acts on. Closes mcpplibs#12
…adable, test generate/audit - summarize() closed a ```diff block after truncating a report.md even when the cut fell outside one, turning the rest of the issue into code. It now adds the fence only when the kept lines leave one open. - gen_exports.py printed "error: N facade problem(s)" to stderr while the facade: lines went to block-buffered stdout, so through a pipe the error came first and generate() failed the nightly run on a facade-only problem. The line now goes to stdout, after the facade: lines. - New GenerateTests/AuditTests cover which generator exits count as a result; test_audit_drift checks both sides of the evidence, and check()'s A-run hook the contents of the restored-cache copy. - The workflow header says what the unit tests cover and what still needs a workflow_dispatch run.
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.
Closes #12.
Problem
check-script-cache-drift.ymlruns only nightly and onworkflow_dispatch, and nothing undertools/tests/importedtools/ci/check_cache_drift.py. A PR that broke the driver merged green. The worst case was a broken verdict that reported "no drift", which the nightly run would not catch either.Change
tools/tests/test_check_cache_drift.py(31 tests, about 25 ms) needs neither clang nor the MinGW sysroot. verify-scripts'unittest discover -s testspicks it up on all three platforms. It covers every item on the issue's checklist:diff_files: changed content, a file on only one side, identical trees.affected_libs:generated/exports/(.incand.depscount once),target/gen/audit/,api-surface.json(only the changed entries), a file missing on one side, files that name no library.unified/write_diff: truncation and its "more diff lines" count, a missing side read as empty,write_diffnever truncates and writes LF.copy_entries: only the affected libraries'.skip/.gate/.audit.json, missing entries skipped, nothing created when there is nothing to copy.summarize: empty without drift; each of the three kinds alone in its own column; only drifting platforms listed; the 120-line excerpt cut; the 60 KB budget;--summarizethroughmain().check:generate,audit,assert_clean/run_step,_snapshotand the clang identity are mocked, andCACHE_DIRpoints to a temp dir. Scenarios: no drift (with the facade exit code 1 that is not drift), no restored cache, A != B, audit A != B, B != C, all at once, noGITHUB_OUTPUT. Each one asserts the exit code,status.json, the evidence files, and thecache_drift/committed_driftlines appended toGITHUB_OUTPUT. It also checks that A runs on the restored cache and B on an emptied one.The workflow header now explains why PRs don't run the workflow and where the driver is tested.
Verification
python3 -m unittest discover -s testsintools/: 107 tests OK.cache_driftignoring audit drift, A compared with itself, B != C computed against A, the cache not emptied before B, the exit code ignoring audit drift, evidence copied from the wrong cache,summarizeskipping audit-only legs, no length budget, a misspelledapi-surface.json, andlimit=0truncating.Not covered, as the issue says: the workflow file itself (step conditions, artifact names, cache keys) and the report job's
ghcalls. Those still need aworkflow_dispatchrun.