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.
89 lines
4.3 KiB
Markdown
89 lines
4.3 KiB
Markdown
# Copilot instructions for shopdb-flask
|
|
|
|
Follow these when suggesting code. They are enforced by a naming/style hook and
|
|
by CI (`.github/workflows/ci.yml`) - suggestions that break them fail the build.
|
|
`CONTRIBUTING.md` is the full authority; this is the short version.
|
|
|
|
## Naming (LOCKED - the hook rejects violations)
|
|
|
|
- **DB tables**: lowercase, concatenated, plural. No underscores, no dashes.
|
|
`machines`, `networkdevices`, `businessunits` - NOT `machine_types`, `BusinessUnits`.
|
|
- **DB columns**: lowercase, concatenated, singular. No underscores.
|
|
`machineid`, `lastzabbixsync`, `isactive` - NOT `machine_id`, `last_zabbix_sync`.
|
|
- **Foreign keys**: referenced table (singular) + `id`: `locationid`, `vendorid`.
|
|
- **Booleans**: `is`/`has` prefix: `isactive`, `isshopfloor`.
|
|
- **Index names**: `idx_<table>_<column>` (underscores allowed here only).
|
|
|
|
### Python
|
|
|
|
- A variable, attribute, function, or dict key that holds a DB value MUST match
|
|
the column name exactly - do NOT convert to snake_case.
|
|
Column `machineid` -> `Machine.machineid`, `{"machineid": 1}`, local `machineid`.
|
|
- Pure code that does NOT mirror a DB field uses normal snake_case (PEP 8):
|
|
`loop_count`, `current_user`, `validate_input()`.
|
|
- Classes: PascalCase, spelled out (`NetworkDevice`, `AssetType`).
|
|
|
|
### JavaScript / Vue
|
|
|
|
- A JS variable holding an API field value matches the API key exactly - do NOT
|
|
camelCase it. API `{"machineid": 1}` -> `response.machineid`, never `machineId`.
|
|
- Components: PascalCase (`AssetDetail.vue`). CSS classes: lowercase-with-dashes.
|
|
|
|
### API
|
|
|
|
- Endpoints: lowercase plural nouns, no underscores/dashes: `/api/networkdevices`.
|
|
- Query params + response keys match column names: `?locationid=5`,
|
|
`{"machineid": 1, "lastzabbixsync": "..."}`.
|
|
|
|
### Allowed acronyms only
|
|
|
|
Universal: id url api http https json jwt sql os ip dns csv pdf cors ttl uuid
|
|
html css orm. Domain: cmm cnc pc usb vnc winrm ssh ssl tls tcp udp smtp ldap
|
|
vlan sso dnc focas clm mtconnect. Anything else: spell it out.
|
|
|
|
### Banned shorthand
|
|
|
|
Never use `cfg ctx mgr req res env util helper` or `db` as a standalone variable
|
|
name. Spell out: `config context manager request response environment utilities`.
|
|
`_bp` is fine only as a suffix with a meaningful prefix (`printers_bp`).
|
|
|
|
## Style (ASCII only)
|
|
|
|
- NO emojis anywhere - code, comments, strings, UI.
|
|
- NO em-dashes, en-dashes, Unicode arrows, or smart quotes. Plain ASCII only.
|
|
- Comments default to NONE. Add one only when the WHY is non-obvious; keep inline
|
|
`#`/`//` comments terse. Docstrings stay normal English.
|
|
- Dark theme is the default; keep UI functional and professional.
|
|
|
|
## Architecture (do not violate)
|
|
|
|
- **Plugins are the product.** Plugin code lives in `plugins/<name>/{models,api,services,schemas}/`
|
|
with a `manifest.json` (single source of truth: name, version, dependencies,
|
|
api_prefix) and a `BasePlugin` subclass in `plugin.py`.
|
|
- **Plugins never import core internals.** Use the contract surface `shopdb.api`
|
|
(e.g. `from shopdb.api import db, Asset, success_response`). Adding to that
|
|
surface is a contract-version bump + a `docs/PLUGIN-HOOKS` update in the same PR.
|
|
- **Migrations, never `db.create_all()`.** The core Alembic chain is in
|
|
`migrations/versions/`; each plugin owns its own chain under
|
|
`plugins/<name>/migrations/`. New schema = a new migration with an idempotent
|
|
guard and a real downgrade. Migrations must run clean on strict MySQL 8.
|
|
- **Asset model is the platform contract.** Physical things are an `Asset` plus a
|
|
plugin subtype row linked by `assetid` (FK, `ON DELETE CASCADE`). Consumables
|
|
with quantities are standalone tables, not assets.
|
|
- **Ledger pattern**: a cached `quantityonhand` moves in the SAME commit as the
|
|
signed transaction row it reflects.
|
|
- **Configuration for endpoint agent**: The endpoint agent's live collector key and base URL are provisioned in the Windows registry `HKLM\SOFTWARE\GE\ShopDB` (values `CollectorKey`, `BaseUrl`), not committed in `appsettings.json`; `appsettings.json` holds only non-secret runtime settings.
|
|
|
|
## Before you finish a change
|
|
|
|
Run the three gates (CI runs the same):
|
|
|
|
```
|
|
python -m pytest tests/ -q
|
|
cd frontend && npx vitest run && npm run build && cd ..
|
|
bash scripts/check-naming-and-style.sh
|
|
```
|
|
|
|
Commits: short present-tense subject, body says WHY. No AI/tool attribution in
|
|
commit messages, code comments, or docs.
|