Skip to content

tests: unit-test check_cache_drift.py's verdict without clang - #15

Open
ZheFeng7110 wants to merge 2 commits into
mcpplibs:mainfrom
ZheFeng7110:test/check-cache-drift
Open

ZheFeng7110 wants to merge 2 commits into
mcpplibs:mainfrom
ZheFeng7110:test/check-cache-drift

Conversation

@ZheFeng7110

Copy link
Copy Markdown
Collaborator

Closes #12.

Problem

check-script-cache-drift.yml runs only nightly and on workflow_dispatch, and nothing under tools/tests/ imported tools/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 tests picks 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/ (.inc and .deps count 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_diff never 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; --summarize through main().
  • check: generate, audit, assert_clean/run_step, _snapshot and the clang identity are mocked, and CACHE_DIR points 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, no GITHUB_OUTPUT. Each one asserts the exit code, status.json, the evidence files, and the cache_drift / committed_drift lines appended to GITHUB_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 tests in tools/: 107 tests OK.
  • I made 10 hand mutations of the driver, and each one fails the new tests. Among them: cache_drift ignoring 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, summarize skipping audit-only legs, no length budget, a misspelled api-surface.json, and limit=0 truncating.

Not covered, as the issue says: the workflow file itself (step conditions, artifact names, cache keys) and the report job's gh calls. Those still need a workflow_dispatch run.

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.
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.

ci: check_cache_drift.py 没有单元测试,PR 也不运行缓存漂移检查

1 participant