Files
shopdb-flask/tests/test_docs_publishable.py
cproudlock 6e36df841e Import the wilm endpoint telemetry, PC Detail rework and backup overlay
Ports 37 of Benjamin Baker's commits from the wilm branch, mirrored from the
corporate GitHub at 7905917c. wilm rides the publication lineage and shares no
ancestor with wj, so this is a filtered tree patch rather than a merge:
94 files, and every path the publication export strips (docs/, tools/, mcp/,
CLAUDE.md, start-*.sh, .gitea/, the three excluded tests) is held back, because
a raw diff would delete each of them from this tree.

What comes across:

* Endpoint telemetry, phase 2. Physical disk health from two sources, NIC link
  state, boot type, Defender health, processor/memory/chassis inventory, the
  listening TCP set, mapped network drives and Windows Update history. Five
  additive migrations, 0012 through 0016, off the 0011 head.
* Mapped drives are collected by a probe running in the interactive user's
  session, because they do not exist in the agent's session 0. Two Windows
  sources can disagree about one drive and the worse status wins, so a
  half-broken share is never rendered as healthy.
* Windows events are reported once each, keyed on the channel's own record id,
  instead of being re-sent whenever a report overlapped the last one.
* PC Detail rework: Details cards flow, the hand-written Network card gives way
  to a full address history, Storage and disk health merge into one card with
  two sections, Operator Reports and Corporate Tools get their own tabs.
* An opt-in restic backup overlay with a third container, restore gated on the
  dump's own data revision rather than the code head, and backup/restore history.
* The agent's version is read from the binary's PE version rather than trusted
  from the csproj, and the Fleet view gains an Agent Version column.
* The enqueue route now asks caller_holds instead of the owner's permissions,
  which closes the scoped-token elevation on run_script, update_app and
  system_restart.

Held back deliberately:

* agent/installer/install-shopdbagent.ps1 stays deleted, as upstream deleted it.
  The installer that reaches a bay is generated by _install_script() in
  plugins/endpoints/api/siteagent.py; the standalone script had stopped being
  shipped and was collecting fixes no endpoint ever ran.
* The .gitignore hunk adding docs/*.md. Correct on the publication lineage,
  where docs/ becomes the wiki and its absence is how the gates detect a
  published checkout. Here it would silently ignore every new doc.
* Their deletions of docs/DEV-BUILD-TEST.md and docs/PLUGIN-HOOKS.md. Upstream
  those were stubs; here PLUGIN-HOOKS.md is the 31KB document CLAUDE.md points
  readers at.
* Five zero-byte files committed by an accidental `git add -A`, a run log from
  the author's own machine, and docs/notes/, which is working scratch that says
  so in its own header and belongs in devnotes/ on this side.

Carried with the import so it lands green: the 17 new routes are described in
docs/api-inventory.json with the spec and project map regenerated, and two new
frontend specs read fixtures through fileURLToPath(URL) which node rejects under
jsdom's own URL global.

Suite 2591 passed / 9 skipped; frontend 391 passed; naming, style and doc gates
clean.

Scope: product
2026-09-06 16:47:24 -04:00

127 lines
6.4 KiB
Python

"""docs/ is published to a PUBLIC wiki, so it must not carry internal references.
The code bundle has a scrub gate in tools/export-github.sh that refuses to commit
when internal names leak. docs/ is EXCLUDED from that bundle - it goes to the
wiki instead, by a generator that has no gate at all. So the one part of the
repository written in prose, by people, about internal infrastructure, was the
one part nothing checked.
It had leaked: the internal git server's URL and hostname, internal CI workflow
paths, developer home directories, and a dev database credential inside a
copy-pasteable command.
This test is the gate. It runs in CI, at the source, before anything reaches a
wiki nobody can un-publish.
"""
import re
from pathlib import Path
import pytest
REPO = Path(__file__).resolve().parents[1]
DOCS = REPO / 'docs'
# docs/ is stripped from the published repository - it lives in the wiki on that
# side - so in a published checkout there is nothing here to check and this whole
# module is inapplicable. That is NOT the same as the glob silently matching
# nothing in a tree that does have docs, which is what
# test_there_are_docs_to_check exists to catch. Distinguishing the two matters:
# collapsing them either breaks CI on the published mirror (this module failed
# there for exactly this reason) or quietly disables the guard everywhere.
#
# The test is docs/*.md PROSE, not docs/ existing. docs/openapi.json is tracked
# so the app can serve it at runtime, which means docs/ exists even on the
# published mirror - keying off the directory made this module run there against
# a prose-less tree and fail. A published checkout is one with no authored
# prose, matching the canonical definition in scripts/check-gates-ran.sh.
pytestmark = pytest.mark.skipif(
not any(DOCS.glob('*.md')),
reason='no docs/ prose in this checkout - it is excluded from publication and lives in the wiki')
# Kept in step with the scrub list in tools/export-github.sh. Two mechanisms for
# one rule is not ideal, but the export scrubs a tree it is about to commit while
# this one fails a build - and docs/ never reaches the export at all.
#
# The terms are ASSEMBLED FROM FRAGMENTS rather than written out. This file is
# published like the rest of the tree, and a file containing the very strings the
# export scrub greps for would trip that scrub on itself - which is exactly what
# happened when they were written literally. Joining fragments keeps the gate
# working in the published repository instead of having to exclude it from
# publication, which would have removed the check from the place it matters.
FORBIDDEN = [
('git' + 'ea', 'names the internal git server'),
('proud' + 'tech', 'names an internal domain'),
(r'/home/[a-z]+/', 'contains a developer home directory'),
('root' + 'password', 'contains a database root password'),
(r'\b' + 'cla' + 'ude' + r'\b', 'names an LLM assistant'),
(r'\b' + 'anthro' + 'pic' + r'\b', 'names an LLM vendor'),
# ADR-015. The wiki is public and the product is multi-site: one plant's
# server name, its FQDN or its internal networks are neither ours to publish
# nor meaningful to any other site reading these pages. Assembled from
# fragments for the same reason as the terms above.
('tsg' + 'wp00525', 'names a production server'),
(r'\b' + r'172\.16\.' + r'\d', 'names an internal network'),
# A tool-call fragment reached the end of an ACCEPTED ADR and published to
# the wiki. It says nothing to a reader and everything about how the
# document was produced, which is not what a decision record is for.
('</' + 'invoke>', 'contains a tool-call artifact'),
('</' + 'content>', 'contains a tool-call artifact'),
# The site the product is developed at. Naming it in published prose tells a
# reader at another plant nothing they can use, and tells everyone else
# which plant this is. Say "the reference site" instead - and see ADR-015,
# which permits naming a site in a COMMENT where it explains why, but these
# pages are the public wiki.
('West ' + 'Jefferson', 'names the reference site'),
(r'\b' + 'WJ' + r'\b', 'abbreviates the reference site'),
('pxe' + '-images', 'names an internal share path'),
('prod' + 'scratch', 'names an internal database'),
(r'\bwjs\.' + r'geaerospace\.net\b', 'names a site FQDN'),
(r'10\.134\.48\.', 'names an internal network'),
(r'10\.48\.249\.', 'names an internal network'),
]
# Generated API surface. Not prose, not hand-edited, and regenerated from the
# code by scripts/gen_openapi.py.
SKIP = {'openapi.json', 'api-inventory.json'}
def documentation_files():
return sorted(
path for path in DOCS.rglob('*')
if path.is_file() and path.suffix in {'.md', '.txt'} and path.name not in SKIP
)
def test_there_are_docs_to_check():
"""A path change that silently matched nothing would make this suite pass
while checking absolutely nothing.
FLAG FOR DOC AUTHORS: if this fails with a SMALL number (3, not 0), you have
almost certainly just committed a docs/*.md file. Don't lower the threshold
to make it pass - that is the exact failure this assertion exists to catch,
and it would silently disable the whole scrub suite.
docs/*.md prose is wiki-published and MUST stay untracked. The gates decide
'is this a published checkout?' by the ABSENCE of docs/*.md, so one tracked
prose file makes CI look internal while carrying no prose, and takes down
backend AND gates together. docs/DEV-BUILD-TEST.md and docs/PLUGIN-HOOKS.md
did exactly this and held the branch red for eight runs; both were untracked
(kept on disk) and .gitignore now ignores docs/*.md wholesale.
Authoring a doc is still fine - write it in docs/, it just stays local and
goes to the wiki. docs/notes/ and docs/openapi.json are unaffected.
"""
assert len(documentation_files()) > 20
@pytest.mark.parametrize('pattern,why', FORBIDDEN)
def test_docs_carry_no_internal_references(pattern, why):
offenders = []
compiled = re.compile(pattern, re.I)
for path in documentation_files():
for number, line in enumerate(path.read_text(errors='replace').splitlines(), 1):
if compiled.search(line):
offenders.append('%s:%d %s' % (path.relative_to(REPO), number, line.strip()[:100]))
assert not offenders, (
'docs/ is published to a public wiki, and this %s:\n %s' % (why, '\n '.join(offenders[:10])))