Files
shopdb-flask/.github/agent-workflow.md
cproudlock 784964c907 Bring the wilm branch into main: endpoints plugin, agent, policies, CSV import
Ports the corporate-GitHub wilm branch onto main, keeping the two branches
separate. Thirteen upstream commits arrive with their authorship intact; the
review fixes and the portability work below are on top.

What arrives:

  endpoints plugin  - a ShopDB agent reporting endpoint state, telemetry,
                      services and interfaces, with a command channel the agent
                      long-polls. Ingest stays on the generic collector route
                      (ADR-006); the agent key is a UI-managed single-scope
                      token whose revocation is an instant kill switch.
  computers policies - Configuration and Business Policies (RMM-style), scope
                      trees validated at write time, actions checked against
                      the endpoints command allowlist. Feature-gated: every
                      route 404s while the setting is off, so enabling it can
                      never half-expose the surface.
  asset CSV import  - templates, a collector script carrying the site path, and
                      a validate-then-commit import. A plugin can own a virtual
                      column plus a post-write row hook, which is how a PC's
                      machine number becomes a controls link without a
                      hand-built relationships sheet.
  agent/            - the Windows agent and its installer.

Contract 0.21.0 -> 0.24.0, additive throughout: register_import_hook (0.22),
mint/list/revoke_service_token (0.23), collector_authorized (0.24). The stability
table had no rows for any of them and now does.

MySQL 5.6 portability. The branch stored three policy columns as sa.JSON, the
only JSON columns in the product, and 5.6 has no JSON type: the migration failed
with a bare syntax error near the word JSON. They are TEXT now, through a
JSONText type decorator, so all seventeen call sites still read and write dicts.
The convention elsewhere is already TEXT (guides.blocksjson,
geenforce.manifestjson).

Review fixes carried on top:

  - six policy GETs were jwt_required(optional=True), which authenticates a
    caller without checking anything; they require computers.view now, and six
    redundant jwt_required decorators are gone
  - the agent installer took a default BaseUrl and CollectorKey, so a mistyped
    run silently pointed an endpoint at the wrong instance; both are mandatory
    and a non-https BaseUrl throws unless -AllowInsecureHttp is passed
  - a committing CSV import wrote no audit row

Documentation: the 34 new routes are described in docs/api-inventory.json, which
is hand-maintained on purpose, and the generated spec now covers 331 paths and
477 operations across 22 surfaces. DEVELOPMENT-SETUP's 1071 troubleshooting row
said "use MySQL 8 for dev" and now gives the actual fix, including the trap that
5.6 downgrades ROW_FORMAT=DYNAMIC to Compact with a warning instead of an error.

Full suite 2123 passed, vitest 260 passed, all seventeen plugin chains migrate
clean on MySQL 5.6 and the naming, docs, parity and read-surface gates are green.
2026-08-28 16:17:17 -04:00

3.9 KiB

Agent workflow rules

Companion to copilot-instructions.md (which owns naming/style/architecture). These cut wasted turns. All are lessons from real sessions.

Environment - know these, do not rediscover

  • Shell is PowerShell: use ; not &&, 2>$null not 2>/dev/null.
  • API container shopdb-flask-wilm-api-1 (Flask, port 5001).
  • DB container shopdb-flask-wilm-db-1 (MySQL 8, root pw root_password_123).
  • SPA is baked into the image (not bind-mounted). Plugin code is bind-mounted read-only.
  • docs/ is stripped to a public wiki mirror - keep working docs out of it.
  • requirements.txt is hash-checked - never hand-edit.

Verify, don't react

  • The terminal "Command failed" banner fires on any non-zero exit or stderr output and is usually a false negative (curl --fail on a 400, pytest/npm/git writing to stderr). Judge success from real output.
  • Read container health via docker inspect --format '{{.State.Health.Status}}' plus a probe without --fail - never eyeball the exit code.

Container runs the image, not your edits

Before running anything in the container that must reflect a change:

  1. Frontend: npm run build, then docker cp frontend/dist/. shopdb-flask-wilm-api-1:/app/frontend/dist.
  2. Backend/scripts/templates: docker cp the files (or rebuild) first.

If a result contradicts a change you just made, suspect stale container code before re-deriving the fix.

Testing

  • Confirm the working directory once, up front.
  • Run the smallest test that proves the point; find the minimal polluter for isolation bugs. Run the full suite only at the end.
  • Clear stale local state before plugin/migration tests: if (Test-Path instance/plugins.json) { Remove-Item instance/plugins.json -Force }.
  • Naming-gate hits inside local venvs (.ci-venv/, env/) are not repo code - do not "fix" vendored libraries.
  • Final gates, exactly as CI: python -m pytest tests/ -q; cd frontend; npx vitest run; npm run build; cd ..; bash scripts/check-naming-and-style.sh.

Migrations and imports

  • Every migration: idempotent guard + real downgrade; must run clean on strict MySQL 8. If you rename indexes in upgrade(), update downgrade() to match.
  • Avoid duplicate indexes: index=True plus an explicit db.Index on the same column creates two.
  • Importers/seeders match by natural key and must be idempotent - prove it by running twice (expect updated, not created). Watch all-or-nothing writes.

Don't offer rollbacks you don't need

State current state plainly; surface a rollback path only for a real regression.

Wilmington (wilm) local-run known failures - do not re-investigate

Running the full python -m pytest tests/ -q on a Windows dev box (not CI) produces a stable set of environmental failures that are NOT code regressions. Treat these as expected locally; judge your change against CI/Linux instead:

  • test_core/test_security_headers.py::test_a_served_upload_is_sandboxed - PermissionError [WinError 32] (served upload file still locked by another process). Windows file-lock timing, not a headers bug.
  • test_plugin_contract.py::test_import_scan_covers_symlinked_plugins - OSError [WinError 1314] (symlink privilege not held). Needs admin/Developer Mode to create symlinks; irrelevant to plugin logic.
  • test_plugin_importguard.py::test_verified_source_signed_ok_tampered_raises - CRLF vs LF (b'# plugin\r\n' == b'# plugin\n'). Git autocrlf checkout, not a signing bug.
  • test_docs_publishable.py and test_docs_versions.py - the local docs/ tree is not the stripped public wiki mirror, so doc-count / PROJECT-MAP assertions fail. Expected off-CI.
  • test_core/test_public_read_surface.py::test_every_get_route_is_gated_or_named_public
    • pre-existing ungated-GET inventory drift; only act on it if YOUR change added a new GET route.

If a run shows ONLY these, the suite is green for our purposes. Anything outside this list is real - investigate it.