diff --git a/CHANGELOG.md b/CHANGELOG.md index 084c0fb..08db49f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ version and its date. Versions follow semantic versioning: a major version when people have to change their setup, a minor one for new skills or abilities, a patch for fixes. +## 1.1.23 - 2026-11-28 + +- Apps and boards can read the project's alarms: every project has the built-in app `alarms`, with the tables `alarms` (the current state of each alarm with the latest filter) and `alarm_events` (one row per status change, with its cause, the device and the row that caused it). `ironflock-templates` shows how an app consumes it (`consumes`, `provider_app: alarms` on a board, the SDK's cross-app connection) and its columns; the board validator checks bindings to both tables like the app's own, and reports a write to them, since only the platform writes alarms. The template schemas describe `alarms` and say that `*` includes it. `ironflock-data` and `ironflock-fleet` answer questions about past alarms from `alarm_events` with SQL. + ## 1.1.22 - 2026-11-27 - Boards can take photos with a form: widget-form's media field (widget-form 2.3.0 and later) stores several photos per save, each resized to a JPEG, as rows of a photo table linked to the record, optionally with where and when each was taken. `board-forms.md` shows the photo table, the files namespace and the two forms (a report with photos, more photos for an existing record), and the board validator checks the namespace (it must take `image/jpeg`), the accepted image types, the photo table's columns and their types, the link to the record and the photo ID's entity key. The widget skill documents the `media-data-submit` event Studio handles for it. diff --git a/VERSION b/VERSION index c442f5e..32ffe12 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.22 +1.1.23 diff --git a/plugins/ironflock-appliance/.claude-plugin/plugin.json b/plugins/ironflock-appliance/.claude-plugin/plugin.json index 4173579..a8e389f 100644 --- a/plugins/ironflock-appliance/.claude-plugin/plugin.json +++ b/plugins/ironflock-appliance/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ironflock-appliance", "displayName": "IronFlock Appliance", - "version": "1.1.22", + "version": "1.1.23", "description": "Add a direct connection from Claude Code to your IronFlock appliance. Configure the appliance’s HTTPS MCP address and sign in to that installation.", "author": { "name": "IronFlock", diff --git a/plugins/ironflock-dev/.claude-plugin/plugin.json b/plugins/ironflock-dev/.claude-plugin/plugin.json index eb06b8a..93f2990 100644 --- a/plugins/ironflock-dev/.claude-plugin/plugin.json +++ b/plugins/ironflock-dev/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ironflock-dev", "displayName": "IronFlock Dev", - "version": "1.1.22", + "version": "1.1.23", "description": "Build on IronFlock: design and scaffold edge apps that keep their state in the app's tables and embed their devices' web UIs in the board, write and validate their .ironflock templates (boards and widgets, data tables, app parameters, remote-access ports, AI agents), and create, change and check the board widgets themselves (@ironflock/widget-* Lit components). Needs the ironflock plugin, which Claude Code installs with it.", "author": { "name": "IronFlock", diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md b/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md index 8328ca7..3b45f93 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md @@ -17,13 +17,14 @@ starter app in `assets/app-template/` follows all of them; scaffold it with 7. [Reading and writing state with the SDK](#reading-and-writing-state-with-the-sdk) 8. [Entity tables: current state, updates and deletes](#entity-tables-current-state-updates-and-deletes) 9. [Following what the board writes](#following-what-the-board-writes) -10. [Commands, device functions and topics](#commands-device-functions-and-topics) -11. [The container on the device](#the-container-on-the-device) -12. [Docker Compose](#docker-compose) -13. [Web UIs on the device](#web-uis-on-the-device) -14. [Several devices](#several-devices) -15. [Devices that register themselves](#devices-that-register-themselves) -16. [Checklist](#checklist) +10. [Reading another app's data](#reading-another-apps-data) +11. [Commands, device functions and topics](#commands-device-functions-and-topics) +12. [The container on the device](#the-container-on-the-device) +13. [Docker Compose](#docker-compose) +14. [Web UIs on the device](#web-uis-on-the-device) +15. [Several devices](#several-devices) +16. [Devices that register themselves](#devices-that-register-themselves) +17. [Checklist](#checklist) ## The parts of an app @@ -461,6 +462,43 @@ A table without an entity key holds one setting for all devices: the newest row is in force. For settings per device or per machine, key the table by the target (see [Several devices](#several-devices)). +## Reading another app's data + +An app reads the shared tables of another app in the same project once it lists +that app under `consumes` in data-template.yml and the project's user has +granted the access. The code opens a read-only handle with `connect_to_app` +(`connectToApp` in JavaScript, `ConnectToApp` in Go) and reads and follows the +provider's tables through it with `get_history` and `subscribe_to_table`, as it +does its own. It cannot write them. + +**The project's alarms** are such an app: every project has the built-in app +`alarms`, and a `*` under `consumes` includes it. The SDK names it with the +constant `ALARMS_APP` (`AlarmsApp` in Go). + +```python +from ironflock import ALARMS_APP + +alarms = await flock.connect_to_app(ALARMS_APP) +current = await alarms.get_history("alarms", {"limit": 100, "filterAnd": [{"latest": True}]}) +await alarms.subscribe_to_table("alarm_events", lambda row, *a, **kw: on_alarm_event(row)) +``` + +| Table | Rows | Columns | +|---|---|---| +| `alarms` | One per version of an alarm; `{"latest": True}` gives the current state of each (entity key `alarm_key`) | `tsp`, `alarm_key`, `alarm_name`, `display_name`, `status` (`OK`, `MINOR`, `MAJOR`, `CRITICAL`, empty while unknown), `status_tsp`, `status_row` (the values of the row that set the status), `observing`, `watched_app`, `watched_app_key`, `watched_backend_key`, `watched_table`, `auto_resolve`, `conditions`, `assessment`, `assigned_to`, `changed_by` | +| `alarm_events` | One per status change, oldest first like every read | `tsp`, `event_id` (a UUID, to keep as a reference), `alarm_key`, `alarm_name`, `display_name`, `from_status`, `to_status`, `cause` (`data`, `reset`, `started`, `stopped`, `trigger_changed`, `deleted`), `watched_app`, `watched_app_key`, `watched_table`, `device_name`, `row_tsp`, `row` (the values of the row that caused the change), `condition` (the condition that matched; empty when the status fell to OK), `changed_by` | + +- Both tables also have `device_key` and `authid`. In `alarm_events`, + `device_key` is the device that wrote the row. +- **Production only.** The alarms exist in production; a development run of the + app reads the project's production alarms, and so does the board. This needs + an SDK release that exports `ALARMS_APP`. +- **Read-only.** Only the platform writes these tables; an app that acts on an + alarm writes to its own tables. The recipients of notifications are not + readable. +- An event carries the row that caused it, so an app with access to `alarms` + sees those values even without access to the watched app. + ## Commands, device functions and topics **Prefer state.** Most things users "command" are desired state: a setpoint, on diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/app-templates.md b/plugins/ironflock-dev/skills/ironflock-templates/references/app-templates.md index 9a022fe..09f2a55 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/app-templates.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/app-templates.md @@ -137,6 +137,20 @@ read them. - To read another app's tables, list it under `consumes:`. Board widgets that bind to those tables then need `provider_app` on their data reference (see board-bindings.md). + - **Alarms are an app too.** Every project has the built-in app `alarms`, with + the project's alarms as two tables: `alarms` (one row per version of an + alarm, current state with the latest filter) and `alarm_events` (one row per + status change). An app that shows or reacts to alarms consumes it like any + other app, and `*` includes it: + + ```yaml + consumes: + - app: alarms + reason: Shows the alarms of each machine on the board + ``` + + The tables are read-only and exist in production only. app-architecture.md + ("Reading another app's data") has the columns and how the code reads them. - **An app that needs host access declares `privileged:`** next to `data:`, with a `reason` the user reads when granting it: diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md index 3d905c2..9fcc839 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md @@ -233,6 +233,26 @@ You can read: - **Another app's table:** add `provider_app: ` to the ref, and list that app under `consumes` in data-template.yml. Only that app's shared tables and transforms can be read. Its private ones are not shared. +- **The project's alarms:** `provider_app: alarms`, with `alarms` or `*` under + `consumes`. `alarms` holds one row per version of an alarm; bind it with + `{latest: true}` (entity key `alarm_key`) for the current state of each alarm. + `alarm_events` holds one row per status change, oldest first like every + table. The validator knows both tables' columns (app-architecture.md, + "Reading another app's data"). Neither can be a form's or a toolbar's target: + only the platform writes them. A board reads production alarms, also while + the app runs in development. + + ```yaml + tableRef: + tablename: alarm_events + provider_app: alarms + format: {time: tsp, alarm: display_name, status: to_status, device: device_name} + queryParams: + limit: 100 + windowPeriod: day + windowLength: 1 + nowMinusPeriods: 0 + ``` There's no arithmetic, ratio, join or derived column in a binding, and no widget computes those either. When a widget needs one, add a transform to diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md index 81a75bd..351e90f 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md @@ -278,7 +278,8 @@ Some values only exist inside a running platform, and a template cannot know the ## Checklist 1. Every `tablename` and column exists in data-template.yml (or under - `provider_app` in a consumed app), and the app's code actually publishes it. + `provider_app` in a consumed app, such as the built-in `alarms` with its + tables `alarms` and `alarm_events`), and the app's code actually publishes it. 2. Every chartconfig key comes from the pinned widget version's schema, and every constant is prefixed. 3. Bindings (board-bindings.md) sit at the right kind of property (valueRef on single values, tableRef diff --git a/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml b/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml index aa0d179..91f5621 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml +++ b/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml @@ -433,7 +433,10 @@ $defs: description: >- Lowercase name of another app whose table this binding reads. That app must be listed under consumes in this app's data-template.yml, and the - project must have granted the data access. + project must have granted the data access. A consumes entry "*" covers + every app. The name alarms is the built-in alarms app that every project + has: its tables alarms and alarm_events are readable like any app's, + read-only, and exist in production only. anyOf: - type: string pattern: "^[a-z0-9._-]+$" diff --git a/plugins/ironflock-dev/skills/ironflock-templates/schemas/data-template/v1.yml b/plugins/ironflock-dev/skills/ironflock-templates/schemas/data-template/v1.yml index 098b1eb..6e7817b 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/schemas/data-template/v1.yml +++ b/plugins/ironflock-dev/skills/ironflock-templates/schemas/data-template/v1.yml @@ -101,7 +101,7 @@ $defs: app: type: string pattern: "^(\\*|[A-Za-z0-9._-]+)$" - description: Name of the provider app whose data backend this app reads, or "*" to consume all non-platform apps' data in the project. Case-insensitive — legacy apps predating the lowercase-name invariant may be named in their original case; the parser normalizes to lowercase. + description: Name of the provider app whose data backend this app reads, or "*" to consume the data of all apps in the project, including alarms. The name alarms is the built-in alarms app that every project has; its tables alarms and alarm_events are readable like any app's, read-only, and exist in production only, so a development run reads the project's production alarms. Case-insensitive — legacy apps predating the lowercase-name invariant may be named in their original case; the parser normalizes to lowercase. reason: type: string description: Human-readable reason for the access, shown to the user when granting diff --git a/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py b/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py index 23bbe3b..c71cb56 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py +++ b/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py @@ -50,6 +50,58 @@ "user_message": "string", } } +#: The built-in alarms app that every project has. Boards read its tables +#: through provider_app: alarms (with alarms or * under consumes), read-only and +#: from production. Its third table, the notification recipients, is not +#: readable. Both tables carry the system columns device_key and authid. +ALARMS_APP = "alarms" +ALARMS_TABLES = { + "alarms": { + "tsp": "timestamp", + "alarm_key": "bigint", + "alarm_name": "string", + "display_name": "string", + "status": "string", + "status_tsp": "timestamp", + "status_row": "json", + "observing": "boolean", + "watched_app": "string", + "watched_app_key": "bigint", + "watched_backend_key": "bigint", + "watched_table": "string", + "auto_resolve": "boolean", + "conditions": "json", + "assessment": "json", + "assigned_to": "bigint", + "changed_by": "string", + "device_key": "bigint", + "authid": "string", + }, + "alarm_events": { + "tsp": "timestamp", + "event_id": "string", + "alarm_key": "bigint", + "alarm_name": "string", + "display_name": "string", + "from_status": "string", + "to_status": "string", + "cause": "string", + "watched_app": "string", + "watched_app_key": "bigint", + "watched_table": "string", + "device_name": "string", + "row_tsp": "timestamp", + "row": "json", + "condition": "json", + "changed_by": "string", + "device_key": "bigint", + "authid": "string", + }, +} +#: Entity keys of the alarms app's tables: {latest: true} on alarms gives the +#: current state of each alarm; alarm_events has none. +ALARMS_ENTITY_KEYS = {"alarms": ["alarm_key"]} +ALARMS_UNREADABLE = {"alarm_notifications"} DEFAULT_COLUMNS, DEFAULT_ROWS = 96, 64 #: DEFAULT_DASHBOARD_STYLE in Studio's src/types/dashboard.ts. DEFAULT_CELL_SIZE, DEFAULT_GRID_GAP = 12, 8 @@ -189,14 +241,20 @@ def warn(self, path: list, message: str) -> None: def columns_of(self, table: str, provider: str | None) -> dict[str, str] | None: """Column -> dataType for a table this board may read, or None when the - columns cannot be known here (another app's table).""" + columns cannot be known here (another app's table, except the built-in + alarms app's).""" if provider: - return None + return ALARMS_TABLES.get(table) if is_alarms(provider) else None if table in SYSTEM_TABLES: return SYSTEM_TABLES[table] return self.data.tables.get(table) +def is_alarms(provider: Any) -> bool: + """Whether a provider_app names the built-in alarms app.""" + return isinstance(provider, str) and provider.lower() == ALARMS_APP + + # -------------------------------------------------------------------------- # Entry point # -------------------------------------------------------------------------- @@ -633,6 +691,14 @@ def check_ref_common(self, ref: dict, path: list, kind: str) -> dict[str, str] | if board.data.present and provider.lower() not in consumes and "*" not in consumes: board.error(path + ["provider_app"], f"reads app '{provider}', which data-template.yml does not list under consumes") columns = None + if isinstance(table, str) and is_alarms(provider): + columns = board.columns_of(table, provider) + if table in ALARMS_UNREADABLE: + board.error(path + ["tablename"], f"'{table}' of the alarms app holds the notification recipients and is not readable; bind alarms or alarm_events") + elif columns is None: + hint = difflib.get_close_matches(table, list(ALARMS_TABLES), n=1) + more = f" (did you mean '{hint[0]}'?)" if hint else "" + board.error(path + ["tablename"], f"the alarms app has no table '{table}'{more}; it offers alarms and alarm_events") if isinstance(table, str) and not provider: columns = board.columns_of(table, None) if columns is None and board.data.present: @@ -871,6 +937,9 @@ def check_write_targets(board: Board, targets: list, writer: str) -> None: if not isinstance(target, dict) or not target.get("tablename"): continue table, column = target.get("tablename"), target.get("column") + if is_alarms(target.get("provider_app")): + board.error(tpath + ["provider_app"], f"the {writer} writes to the alarms app, whose tables are read-only") + continue columns = board.columns_of(table, None) if columns is None: if board.data.present: @@ -1005,12 +1074,16 @@ def one_row_reason(board: Board, ref: dict) -> str | None: if not isinstance(limit, bool) and isinstance(limit, (int, float)) and limit == 1: return "limit 1" table = ref.get("tablename") - if ref.get("provider_app") or not isinstance(table, str) or table not in board.data.tables: + alarms = is_alarms(ref.get("provider_app")) + if alarms: + if table not in ALARMS_TABLES: + return None + elif ref.get("provider_app") or not isinstance(table, str) or table not in board.data.tables: return None # another app's table or a transform: its entity key is unknown here filters = qp.get("filterAnd") if isinstance(qp.get("filterAnd"), list) else [] if not any(isinstance(f, dict) and f.get("latest") for f in filters): return None - keys = board.data.entity_keys.get(table) + keys = ALARMS_ENTITY_KEYS.get(table) if alarms else board.data.entity_keys.get(table) if not keys: return f"the latest filter on '{table}', which has no entity key, keeps its single newest row" pinned = { diff --git a/plugins/ironflock/.claude-plugin/plugin.json b/plugins/ironflock/.claude-plugin/plugin.json index 27ff323..793fb46 100644 --- a/plugins/ironflock/.claude-plugin/plugin.json +++ b/plugins/ironflock/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ironflock", "displayName": "IronFlock", - "version": "1.1.22", + "version": "1.1.23", "description": "Connect Claude to IronFlock in the cloud with browser sign-in. Work with devices, apps, alarms, logs and project data. Add the optional IronFlock Appliance plugin for a direct connection to a local installation.", "author": { "name": "IronFlock", diff --git a/plugins/ironflock/skills/ironflock-data/SKILL.md b/plugins/ironflock/skills/ironflock-data/SKILL.md index f297fd9..4c1c0ba 100644 --- a/plugins/ironflock/skills/ironflock-data/SKILL.md +++ b/plugins/ironflock/skills/ironflock-data/SKILL.md @@ -116,6 +116,16 @@ Patterns: anyone; never select, filter, join or group on them. Only whether a value is set can be counted (`count(*) FILTER (WHERE col IS NOT NULL)`). If the person wants the value, explain that only the app itself can read it. +- **Alarms are tables too.** The project's alarms are the data of the + built-in app Alarms, listed by `get_schema` like any app: `alarms` holds + one row per version of an alarm (its entity key is `alarm_key`, so its + current state is the newest row per `alarm_key`), and `alarm_events` one + row per status change, with `from_status`, `to_status`, the `cause`, the + device (`device_key`, `device_name`), the row that caused the change + (`row_tsp`, `row`) and the `condition` that matched. Queries, transforms + and boards read them like any table ("how often did the press alarm go + critical last week?"); nobody writes them but the platform. They hold + production alarms only. - **Private tables.** An app may keep tables private. A query on one is refused by design: tell the person the app keeps that data to itself, and do not try other ways to read it. diff --git a/plugins/ironflock/skills/ironflock-fleet/SKILL.md b/plugins/ironflock/skills/ironflock-fleet/SKILL.md index dc1108a..494b2dc 100644 --- a/plugins/ironflock/skills/ironflock-fleet/SKILL.md +++ b/plugins/ironflock/skills/ironflock-fleet/SKILL.md @@ -169,6 +169,13 @@ until someone resets it in Studio. An alarm can be configured but not active which alarms are active but OK, and which are not watching at all. - To see what raised an alarm, read the data of the table it watches around the time it fired (`ironflock-data`). +- An alarm's state and history are also tables of the built-in app Alarms, + which SQL queries, transforms and boards read like any app's data: + `alarms` (one row per version of each alarm) and `alarm_events` (one row + per status change, with the cause, the device and the row that caused it). + Questions about the past ("how often did it fire this month?", "which + device raised it?") are answered from `alarm_events` with `ironflock-data`; + the current state comes from `list_alarms`. - Before `create_alarm` or a change of a trigger with `update_alarm`, read the exact app, table and column names with `get_schema`. Do not guess them. Agree the conditions, the severities and the recipients with the person @@ -180,7 +187,8 @@ until someone resets it in Studio. An alarm can be configured but not active - `update_alarm` replaces each part you send (the trigger, the recipients) completely: read the alarm with `list_alarms` and send everything that should remain. -- `delete_alarm` removes the alarm and its whole history, irreversibly. +- `delete_alarm` removes the alarm, irreversibly; its status changes stay + in `alarm_events`, the deletion as the last of them. When someone wants an alarm to stop firing or to be quiet, offer to pause it instead (`update_alarm`, not watching); delete only after an explicit yes to deleting the named alarms. diff --git a/tests/boards/alarms-not-consumed.yml b/tests/boards/alarms-not-consumed.yml new file mode 100644 index 0000000..181b322 --- /dev/null +++ b/tests/boards/alarms-not-consumed.yml @@ -0,0 +1,23 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# Reading the built-in alarms app needs alarms (or '*') under consumes in +# data-template.yml, like any other app. +# +# expect: ERROR widgets[0].chartconfig.columns[0].values.tableRef.provider_app :: reads app 'alarms', which data-template.yml does not list under consumes +name: alarms-not-consumed +widgets: + - layout_id: events + package_name: widget-table + chartconfig: + title: $str:Alarm events + columns: + - header: $str:Alarm + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: display_name} + queryParams: {limit: 100} +layout: + gridLayout: + - {id: events, x: 0, y: 0, w: 96, h: 64} diff --git a/tests/boards/alarms-wildcard.yml b/tests/boards/alarms-wildcard.yml new file mode 100644 index 0000000..578151b --- /dev/null +++ b/tests/boards/alarms-wildcard.yml @@ -0,0 +1,34 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# A consumes entry '*' covers the built-in alarms app too, so this board may +# read alarm_events through provider_app: alarms, and its columns are checked. +# consumes: * +# +# expect-none: widgets[0].chartconfig.columns[0].values.tableRef.provider_app +# expect-none: widgets[0].chartconfig.columns[0].values.tableRef.format.value +# expect: ERROR widgets[0].chartconfig.columns[1].values.tableRef.format.value :: table 'alarm_events' has no column 'status' (did you mean +name: alarms-wildcard +widgets: + - layout_id: events + package_name: widget-table + chartconfig: + title: $str:Alarm events + columns: + - header: $str:Cause + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: cause} + queryParams: {limit: 100} + - header: $str:Status + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: status} + queryParams: {limit: 100} +layout: + gridLayout: + - {id: events, x: 0, y: 0, w: 96, h: 64} diff --git a/tests/boards/alarms.yml b/tests/boards/alarms.yml new file mode 100644 index 0000000..6c9962e --- /dev/null +++ b/tests/boards/alarms.yml @@ -0,0 +1,135 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# The built-in alarms app: data-template.yml consumes alarms, and the board reads +# its tables through provider_app: alarms. Widget 0 lists the status changes +# from alarm_events, widget 1 the current state of each alarm (the latest +# filter on alarms, whose entity key is alarm_key). The others bind a column +# alarm_events does not have, the recipients table, which is not readable, a +# misspelt table, and a toolbar that writes to the read-only alarm tables. +# consumes: alarms +# +# expect-none: widgets[0].chartconfig.columns[0].values.tableRef.provider_app +# expect-none: widgets[0].chartconfig.columns[0].values.tableRef.tablename +# expect-none: widgets[0].chartconfig.columns[0].values.tableRef.format.value +# expect-none: widgets[0].chartconfig.columns[1].values.tableRef.format.value +# expect-none: widgets[0].chartconfig.columns[2].values.tableRef.format.value +# expect-none: widgets[0].chartconfig.columns[2].values.tableRef.queryParams.filterAnd[0].column +# expect-none: widgets[1].chartconfig.columns +# expect-none: widgets[1].chartconfig.columns[0].values.tableRef.format.value +# expect-none: widgets[1].chartconfig.columns[1].values.tableRef.format.value +# expect: ERROR widgets[2].chartconfig.columns[0].values.tableRef.format.value :: table 'alarm_events' has no column 'severity' +# expect: ERROR widgets[3].chartconfig.columns[0].values.tableRef.tablename :: holds the notification recipients and is not readable +# expect: ERROR widgets[4].chartconfig.columns[0].values.tableRef.tablename :: the alarms app has no table 'alarm_event' (did you mean 'alarm_events'?) +# expect: ERROR widgets[5].chartconfig.tools[0].targetColumn.provider_app :: the toolbar writes to the alarms app, whose tables are read-only +name: alarms +widgets: + - layout_id: events + package_name: widget-table + chartconfig: + title: $str:Alarm events + columns: + - header: $str:Alarm + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: display_name} + queryParams: {limit: 100} + - header: $str:Device + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: device_name} + queryParams: {limit: 100} + - header: $str:New status + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: to_status} + queryParams: + limit: 100 + filterAnd: + - {column: cause, operator: '=', value: data, dataType: string} + - layout_id: current + package_name: widget-table + chartconfig: + title: $str:Alarms + columns: + - header: $str:Alarm + type: $str:string + values: + tableRef: + tablename: alarms + provider_app: alarms + format: {value: display_name} + queryParams: + limit: 100 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - header: $str:Status + type: $str:state + values: + tableRef: + tablename: alarms + provider_app: alarms + format: {value: status} + queryParams: + limit: 100 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - layout_id: unknown-column + package_name: widget-table + chartconfig: + columns: + - header: $str:Severity + type: $str:string + values: + tableRef: + tablename: alarm_events + provider_app: alarms + format: {value: severity} + queryParams: {limit: 100} + - layout_id: recipients + package_name: widget-table + chartconfig: + columns: + - header: $str:Recipients + type: $str:string + values: + tableRef: + tablename: alarm_notifications + provider_app: alarms + format: {value: notification} + queryParams: {limit: 100} + - layout_id: misspelt + package_name: widget-table + chartconfig: + columns: + - header: $str:Alarm + type: $str:string + values: + tableRef: + tablename: alarm_event + provider_app: alarms + format: {value: display_name} + queryParams: {limit: 100} + - layout_id: write-alarms + package_name: widget-toolbar + chartconfig: + orientation: $str:horizontal + tools: + - label: $str:Acknowledge + buttonValue: $str:OK + targetColumn: {tablename: alarms, column: status, dataType: string, provider_app: alarms} +layout: + gridLayout: + - {id: events, x: 0, y: 0, w: 48, h: 32} + - {id: current, x: 48, y: 0, w: 48, h: 32} + - {id: unknown-column, x: 0, y: 32, w: 24, h: 26} + - {id: recipients, x: 24, y: 32, w: 24, h: 26} + - {id: misspelt, x: 48, y: 32, w: 24, h: 26} + - {id: write-alarms, x: 72, y: 32, w: 24, h: 26} diff --git a/tests/run.py b/tests/run.py index 330eb06..9a155cf 100644 --- a/tests/run.py +++ b/tests/run.py @@ -14,7 +14,8 @@ `# offline: ` line is validated with --offline: its widget configs are not walked against their definition schemas, for a board that pins a widget version not yet on npm (the reason says which, and what to change once - it is published). + it is published). A board with `# consumes: [, ...]` lines is + validated with those apps added under `consumes` in data-template.yml. Then the starter app: assets/app-template must produce no findings at all, and scripts/new_app.py must scaffold an app from it that keeps no trace of the @@ -65,6 +66,7 @@ EXPECT = re.compile(r"^# expect:\s*(ERROR|WARN)\s+(\S+)\s+::\s+(.*)$") EXPECT_NONE = re.compile(r"^# expect-none:\s*(\S+)\s*$") OFFLINE = re.compile(r"^# offline:\s*\S") +CONSUMES = re.compile(r"^# consumes:\s*(.+?)\s*$") def validate(app: Path, name: str, *flags: str) -> list[tuple[str, str, str]]: @@ -79,7 +81,13 @@ def run_board(board: Path) -> list[tuple[str, str, str]]: app = Path(tmp) / "app" shutil.copytree(ROOT / "app", app) shutil.copy(board, app / ".ironflock" / "board-template.yml") - offline = any(map(OFFLINE.match, board.read_text().splitlines())) + lines = board.read_text().splitlines() + offline = any(map(OFFLINE.match, lines)) + consumed = [a.strip() for m in map(CONSUMES.match, lines) if m for a in m[1].split(",") if a.strip()] + if consumed: + data_template = app / ".ironflock" / "data-template.yml" + entries = "".join(f" - app: '{a}'\n reason: Shows its data on the board\n" for a in consumed) + data_template.write_text(data_template.read_text(encoding="utf-8") + "consumes:\n" + entries, encoding="utf-8") return validate(app, board.name, *(["--offline"] if offline else []))