ADR-013 Phase 5: lean per-site builds - build-site.sh + import-guard audit

The lean-build endgame: a site ships carrying only the plugins it chose.

- scripts/build-site.sh: reads a site profile, resolves the hard-dependency
  closure from manifests, builds the frontend with SITE_PLUGINS (stage-frontend
  carries only those plugins), and stages a backend tree of core + only the
  chosen plugin dirs. An unchosen plugin is in neither the bundle nor the tree.
- Core lazy-import guard: `flask seed demo` hard-imported the 5 asset subtype
  models, which would crash a lean build missing any of those plugins. Now
  guarded (a missing model skips its demo section).
- test_lean_build_guards.py: statically asserts NO core (shopdb/core, shopdb/cli)
  import of a plugin is unguarded - a lean build omitting that plugin would
  otherwise crash. 0 unguarded today.

Pilot verified: a lean build (machines + printers) carries only machines +
printers code - PartsKiosk / ManifestEditor / USBLabelBatch / KnowledgeBaseDetail
/ EmployeeDirectory are absent from the bundle, and only machines/printers plugin
dirs stage into the backend. (Sidebar labels for absent plugins remain - the
accepted small plugin-aware core remainder.) Guard test + naming green.
This commit is contained in:
cproudlock
2026-07-19 00:08:35 -04:00
parent c6a1e07a6c
commit da3cb37be8
3 changed files with 147 additions and 5 deletions

View File

@@ -579,6 +579,8 @@ def seed_demo(force):
serialnumber=None, subtype_kwargs=None):
# create one Asset + its plugin subtype row, idempotent on assetnumber.
# returns the Asset, or None when the plugin type is not installed.
if subtype_model is None:
return None # plugin absent on a lean build - skip its demo rows
atype = AssetType.query.filter_by(assettype=assettype_name).first()
if not atype:
return None
@@ -602,11 +604,21 @@ def seed_demo(force):
made['assets'] += 1
return asset
from plugins.machines.models import Machine
from plugins.computers.models import Computer
from plugins.printers.models import Printer
from plugins.network.models import NetworkDevice
from plugins.measuringtools.models import MeasuringTool
# Guarded so demo seeding still works on a lean build that omits any of
# these plugins (ADR-013 Phase 5): a missing model just skips its section.
def _subtype_model(modulename, classname):
try:
module = __import__(f'plugins.{modulename}.models',
fromlist=[classname])
return getattr(module, classname)
except ImportError:
return None
Machine = _subtype_model('machines', 'Machine')
Computer = _subtype_model('computers', 'Computer')
Printer = _subtype_model('printers', 'Printer')
NetworkDevice = _subtype_model('network', 'NetworkDevice')
MeasuringTool = _subtype_model('measuringtools', 'MeasuringTool')
machines = [
('MILL-01', 'Haas VF-2 Mill', 'In Use', 'Cell A', 'Machining'),