Skip to content

refactor(nse): migrate to shared go-api/store/templates package (PR 7) - #3

Merged
0sm0s1z merged 1 commit into
mainfrom
feature/scanner-templates-fix-pr7
Apr 23, 2026
Merged

0sm0s1z merged 1 commit into
mainfrom
feature/scanner-templates-fix-pr7

Conversation

@0sm0s1z

@0sm0s1z 0sm0s1z commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of the scanner-templates-fix sprint (PR 7 / 8). Bumps go-api to v0.0.18 (which introduced `sirius/store/templates` in PR 6) and replaces the local NSE canonicalization helper + key string literals with the shared package's helpers.

  • `internal/nse/sync.go`: drop local `canonicalScriptID`; route writes through `templates.WriteNseScript`; key construction via `templates.NseScriptKey`.
  • `internal/nse/types.go`: re-export Valkey key constants as aliases of the shared package so existing call sites/tests keep compiling.
  • `internal/nse/sync_test.go`: tests now exercise `templates.CanonicalScriptID` directly.

No wire-format change. The shared package's NseScriptRecord is byte-compatible with the existing local ScriptContent envelope (same JSON tags), so previously-written `nse:script:*` entries decode unchanged.

Test plan

  • `go build ./...`
  • `go test -short ./internal/nse/...` (canonical + sync round-trip tests pass)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf96d0fdf5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/nse/sync.go
Comment on lines +304 to +307
script, exists := manifest.Scripts[canonicalID]
if !exists {
script, exists = manifest.Scripts[scriptID]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle legacy .nse manifest keys for canonical UI IDs

UpdateScriptFromUI claims to accept both canonical IDs and legacy extension IDs, but the lookup only tries manifest.Scripts[canonicalID] and manifest.Scripts[scriptID]. When the on-disk manifest still uses <name>.nse keys (as your new tests describe), a canonical UI ID like acarsd-info misses both entries and returns "script not found", so valid scripts cannot be edited. Add a fallback for the legacy .nse key (or normalize manifest keys before lookup).

Useful? React with 👍 / 👎.

Comment thread internal/nse/sync.go
Comment on lines +167 to +170
canonicalID := templates.CanonicalScriptID(id)

// Get script content from ValKey first (highest priority)
globalContent, err := sm.getScriptContent(context.Background(), id)
globalContent, err := sm.getScriptContent(context.Background(), canonicalID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve legacy script content during key canonicalization

syncScriptContent now reads script data only via the canonical key (templates.NseScriptKey(canonicalID)) and never checks the legacy nse:script:<id>.nse entries written by prior versions. During upgrade, existing edited content in old keys is treated as missing, then the local file is written to the new key, which effectively drops user edits from the active path. A legacy-key fallback/migration read is needed before writing canonical keys.

Useful? React with 👍 / 👎.

@0sm0s1z 0sm0s1z closed this Apr 23, 2026
@0sm0s1z 0sm0s1z reopened this Apr 23, 2026
Bump go-api to v0.0.18 and replace the local CanonicalScriptID helper
plus the hand-rolled key prefixes with the shared package constants
and helpers. Re-export the key constants from internal/nse/types.go
as aliases so existing call sites compile unchanged.

Wire the script-content writer through templates.WriteNseScript so
canonicalization is enforced in one place.
@0sm0s1z
0sm0s1z force-pushed the feature/scanner-templates-fix-pr7 branch from 1aad183 to 3d3cd24 Compare April 23, 2026 03:48
@0sm0s1z
0sm0s1z merged commit a031480 into main Apr 23, 2026
1 check passed
@0sm0s1z
0sm0s1z deleted the feature/scanner-templates-fix-pr7 branch April 23, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant