fix(transport): import diff compares secrets and bindings; preview honours the name map; CI lookups; area paths; no Rename where unsupported (TRN-2, TRN-3, TRN-6, TRN-7, TRN-8, TRN-9, WP2 tasks 2.4+2.5)
2.4 — ArtifactDiff: - TRN-2: secret-bearing values (data-connection primary/backup config, DB connection string, external-system auth, SMTP credentials, SMS token) are compared by SHA-256 and reported value-free as <present> -> <changed>, so a changed endpoint no longer reads Identical and is force-skipped. - TRN-6: the instance diff resolves each existing binding's DataConnectionId to its name and compares it (a rebind OPC1 -> OPC2 is Modified); State is no longer compared (the import never carries a live state). 2.5 — BundleImporter / ManagementActor / Central UI: - TRN-3: PreviewAsync takes an optional BundleNameMap (additive optional param); under a MapToExisting redirect the connection/instance diffs, connection auto-match and unresolved-connection blocker run against the mapped target. The CLI import path passes its explicit --map-site/--map-connection redirects to the preview before the blocker gate; the Central UI re-runs the preview under the Map-step choices at Confirm. Apply binds a CreateNew site/connection whose identifier/name already exists to that row instead of inserting a duplicate the unique index rejects. - TRN-7: connection, instance, instance-template and composition/base-template lookups match exact spelling first, then case-insensitively. - TRN-8: InstanceDto gains the additive AreaPath (root->leaf); the exporter fills it and the importer resolves/creates areas level by level under their real parent. A legacy leaf-only bundle with an ambiguous leaf resolves deterministically and adds an ImportResult warning. - TRN-9: Rename is rejected by ApplyAsync for Site, DataConnection, SmtpConfiguration and SmsConfiguration (ImportRenameSupport); the UI does not offer it there and the CLI rename policy falls back to Skip with a warning. Also moves a doc comment misplaced by the 2.6 commit. Reflection round-trip guard (RoundTripEquivalenceTests) re-run: green.
This commit is contained in:
@@ -22,7 +22,7 @@ As of M8 (T18), Transport is no longer limited to central-only configuration: it
|
||||
- Move **site-scoped configuration** (T18): `Site` definitions, site-scoped `DataConnection`s (protocol connections — distinct from External-System `DatabaseConnection`s), and `Instance`s along with their `InstanceAttributeOverride` / `InstanceAlarmOverride` / `InstanceNativeAlarmSourceOverride` / `InstanceConnectionBinding` children and `Area` membership (carried by name).
|
||||
- Reconcile cross-environment site identifiers and connection names through the **name-mapping subsystem** (`BundleNameMap`): auto-match by identifier/name, operator override via the import-wizard Map step or CLI flags, and per-conflict create-or-bind resolution (see "Name Mapping").
|
||||
- Compute a **per-line (Myers) diff** for code fields on Modified artifacts (T20) via the pure `LineDiffer`, embedding a size-capped structured line diff in each `ArtifactDiff`. Two independent caps guard the diff: a 400-line **output** cap on the emitted hunk list, and — as of arch-review 05 (Task 22) — a `MaxInputLines` **input** cap (4000 combined lines) that short-circuits the O((N+M)²) Myers trace to a summary-only result (`Truncated = true`, add/remove totals only) so a bloated or crafted bundle cannot OOM the active central node from the import preview.
|
||||
- Serialize and deserialize all transportable entity types to/from bundle DTOs, carving secret fields into an isolated `SecretsBlock`. A template travels with **all** of its child collections — `TemplateAttribute`, `TemplateAlarm`, `TemplateScript`, `TemplateComposition`, and `TemplateNativeAlarmSource` (including `IsInherited` placeholder rows, which the collision detector depends on) — each field-faithful on Add and reconciled add/update/delete on Overwrite. Field completeness is verified by a reflection round-trip guard over every writable property (Add + Overwrite), and includes the fields earlier revisions dropped: the derived-lock flag `LockedInDerived` on attributes/alarms/scripts, script cadence/timeout (`MinTimeBetweenRuns` / `ExecutionTimeoutSeconds`), and — for instances — the real `AreaName` (the exporter previously emitted `null`, half-shipping the Area-by-name feature). Carrying the native alarm sources is what keeps an imported `InstanceNativeAlarmSourceOverride` from dangling against a source the target template would otherwise lack.
|
||||
- Serialize and deserialize all transportable entity types to/from bundle DTOs, carving secret fields into an isolated `SecretsBlock`. A template travels with **all** of its child collections — `TemplateAttribute`, `TemplateAlarm`, `TemplateScript`, `TemplateComposition`, and `TemplateNativeAlarmSource` (including `IsInherited` placeholder rows, which the collision detector depends on) — each field-faithful on Add and reconciled add/update/delete on Overwrite. Field completeness is verified by a reflection round-trip guard over every writable property (Add + Overwrite), and includes the fields earlier revisions dropped: the derived-lock flag `LockedInDerived` on attributes/alarms/scripts, script cadence/timeout (`MinTimeBetweenRuns` / `ExecutionTimeoutSeconds`), and — for instances — the real `AreaName` (the exporter previously emitted `null`, half-shipping the Area-by-name feature) plus, since 2026-12-03 (TRN-8), the additive `AreaPath` (root→leaf names): the importer resolves the area level by level and creates any missing level under its real parent, since the same leaf name may sit under two parents. A pre-TRN-8 bundle carries only the leaf; an ambiguous leaf then resolves deterministically (a root-level area, else the lowest id) with an `ImportResult.Warnings` entry instead of taking whichever row came back first. Carrying the native alarm sources is what keeps an imported `InstanceNativeAlarmSourceOverride` from dangling against a source the target template would otherwise lack.
|
||||
- Encrypt content with AES-256-GCM + PBKDF2-SHA256 (600 000 iterations) when a passphrase is supplied; leave content plaintext with a UI warning and an `UnencryptedBundleExport` audit event when none is given.
|
||||
- Validate `manifest.json` on upload: format version gating, SHA-256 content hash verification.
|
||||
- **Optionally sign** exported bundles (ECDSA P-256 detached signature in `manifest.sig`) and enforce an import-side signature policy against a trust store — off by default (ScadaBridge#45; see "Bundle Signing").
|
||||
@@ -97,7 +97,7 @@ The manifest is plaintext so the import wizard can preview bundle contents and s
|
||||
### `content.json` / `content.enc`
|
||||
|
||||
- One top-level array per entity type, POCO shapes serialized via `System.Text.Json`. As of schema 1.1 (T18) this includes `sites`, `dataConnections`, and `instances` arrays (`SiteDto`, `DataConnectionDto`, `InstanceDto` + its override-child and connection-binding DTOs) alongside the existing central-config arrays.
|
||||
- Secret fields (API key hashes, SMTP password, external system credentials, DB connection passwords) live in a nested `secrets` block on each affected entity. Per the D3 "carry full config (encrypted secrets)" decision, a `DataConnection`'s `PrimaryConfiguration` / `BackupConfiguration` (endpoint + credentials) also ride inside this encrypted `SecretsBlock`; they appear in diffs as presence-only and are never echoed in plaintext. A `Site`'s `NodeA`/`NodeB` and `GrpcNodeA`/`GrpcNodeB` addresses travel as ordinary (non-secret) `SiteDto` fields.
|
||||
- Secret fields (API key hashes, SMTP password, external system credentials, DB connection passwords) live in a nested `secrets` block on each affected entity. Per the D3 "carry full config (encrypted secrets)" decision, a `DataConnection`'s `PrimaryConfiguration` / `BackupConfiguration` (endpoint + credentials) also ride inside this encrypted `SecretsBlock`; they appear in diffs presence-only and are never echoed in plaintext. **Secret values are still compared (2026-12-03, TRN-2):** the preview hashes both sides (SHA-256) and, when a value present on both sides differs, reports the value-free marker `<present>` → `<changed>`, so the row classifies **Modified**. Before, only a presence flip counted, so a changed OPC UA endpoint (or DB connection string, external-system auth, SMTP credentials, SMS token) read *Identical* and was force-skipped, and an Overwrite driven by an unrelated field replaced the value unseen. A `Site`'s `NodeA`/`NodeB` and `GrpcNodeA`/`GrpcNodeB` addresses travel as ordinary (non-secret) `SiteDto` fields.
|
||||
- The whole `content` blob is AES-256-GCM encrypted with a key derived via PBKDF2-SHA256 (600 000 iterations) from the user's passphrase, with per-bundle random salt and per-encryption random IV.
|
||||
- Unencrypted bundles are allowed but the UI warns and audit-tags them `UnencryptedBundleExport`.
|
||||
|
||||
@@ -234,7 +234,7 @@ Upload → Passphrase → Diff → Confirm → Result. The **Map** step is not a
|
||||
**Step 4 — Diff & resolve conflicts.** For each artifact in the bundle, compare to existing by name:
|
||||
|
||||
- **Identical** (field-by-field) → marked, auto-skipped, cannot be selected.
|
||||
- **Modified** → shows a real per-line `+/-` diff for code fields (`TemplateScript.Code`, `SharedScript.Code`, `ApiMethod.Script`), rendered by the shared `LineDiffView` component from the structured `lineDiff` payload (T20). User picks Skip / Overwrite / Rename.
|
||||
- **Modified** → shows a real per-line `+/-` diff for code fields (`TemplateScript.Code`, `SharedScript.Code`, `ApiMethod.Script`), rendered by the shared `LineDiffView` component from the structured `lineDiff` payload (T20). User picks Skip / Overwrite / Rename — **Rename is not offered for a Site, DataConnection, SmtpConfiguration or SmsConfiguration (TRN-9, 2026-12-03)**: it was silently treated as Skip for sites/connections and wrote a junk second SMTP/SMS row (mangled Host / AccountSid) that delivery never used. `ApplyAsync` rejects such a resolution (`ImportRenameSupport`), and the CLI's `--on-conflict rename` falls back to Skip for those types with a result warning.
|
||||
- **New** → marked `+ Add`. User can opt to skip individually.
|
||||
|
||||
Bulk "Apply to all" at the top (Overwrite / Skip / Rename), overridable per row. Summary line at the bottom: "5 add · 2 overwrite · 1 skip · 0 rename".
|
||||
@@ -302,7 +302,7 @@ Site identifiers and connection names are environment-specific, so a bundle expo
|
||||
|
||||
**Identity keys.** Sites are matched by `SiteIdentifier`; connections by the **site-qualified** key `{SiteIdentifier}/{Name}`; instances by `UniqueName`.
|
||||
|
||||
**Auto-match → operator override → apply.** The importer first auto-matches every source site and connection against the target by these identity keys. The operator confirms/overrides via the Central UI **Map step** (Step 3) or the CLI `--map-site` / `--map-connection` / `--create-missing-*` flags. References that neither auto-match nor are set to Create-new become **blocker rows** (UI) — or, on the CLI without `--create-missing-sites` / `--create-missing-connections`, abort before apply.
|
||||
**Auto-match → operator override → apply.** The importer first auto-matches every source site and connection against the target by these identity keys. **The preview honours the name map (2026-12-03, TRN-3):** `PreviewAsync` takes an optional `BundleNameMap`; under a MapToExisting redirect, the connection / instance diffs, the connection auto-match and the unresolved-connection blocker run against the **mapped** target site and connection. The CLI import passes its explicit `--map-site` / `--map-connection` redirects to the preview before the blocker gate (a connection present only on the mapped site used to be a blocker no mapping could clear), and the Central UI re-runs the preview under the Map-step choices when Confirm is pressed. On apply, a Create-new for a site identifier or a `(site, connection)` name the target already holds binds to that existing row (its own Skip/Overwrite resolution then applies) instead of inserting a duplicate the unique index rejects. **Site-scoped and template-reference lookups are case-insensitive (TRN-7)** — connections, instances, the instance's template, and the composition / inheritance rewire fallbacks match exact spelling first, then case-insensitively, the way the database collation and its unique indexes do. **Instance diff (TRN-6):** a binding's bound connection is compared by name (the existing FK is resolved per site), and `State` is no longer compared — the import never carries a live state, so a State-only difference read Modified and an Overwrite reset a live instance to `NotDeployed` for nothing. The operator confirms/overrides via the Central UI **Map step** (Step 3) or the CLI `--map-site` / `--map-connection` / `--create-missing-*` flags. References that neither auto-match nor are set to Create-new become **blocker rows** (UI) — or, on the CLI without `--create-missing-sites` / `--create-missing-connections`, abort before apply.
|
||||
|
||||
**Template library reads (review 2026-10-21 04/P4 + 08/P1).** A preview and each apply attempt read the target template library **once**, through body-free projections (`GetTemplateStubsAsync` for id/name maps, `GetAllTemplatesForAnalysisAsync` — untracked, members and lock flags but no script bodies — where members or edges are needed), held on a per-session `TemplateLibrary` and threaded to every consumer: preview diff names, blocker and locked-override scans, apply-time validation, the composition/inheritance rewire fallbacks (formerly a full library reload *inside* the per-template loop), the instance pass's name→id map (overlaid with the change tracker's just-flushed templates), the acyclicity guard and the stale-instance expansion. The full tracked graph is loaded only for the templates the bundle **Overwrites** (`GetTemplatesWithChildrenAsync` by name), since their child syncs mutate it. The acyclicity guard reads the change tracker's staged templates overlaid on that snapshot — the untouched part of the graph has not changed during the apply. Instance lookups are batched by name set (`ITemplateEngineRepository.GetInstancesByUniqueNamesAsync`, one tracked + hydrated read for preview and one for the instance pass, Rename targets included), and the preview resolves an existing instance's template / site / area names from the library, one site list and one area list per site, and reads shared scripts and external systems once each.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user