fix(topdata): let pinned TLK ids evict stale state owners
ci / ci (pull_request) Successful in 3m17s
ci / ci (pull_request) Successful in 3m17s
The custom palette taxonomy (#46) pins display strings to fixed TLK ids in tlk/custom.tlk.yml. registerInlineAtID demanded those ids be free, but .tlk_state.json is a gitignored, per-machine cache: on any machine built before #46, a ref could have dynamically grabbed a now-pinned id (e.g. feat:yuanti/alternate_form.feat holding 2689), failing the build with "TLK id N is already reserved by ...". Make the pin authoritative over the cache: a stale cached owner on a pinned id is evicted and reallocated a fresh id when next made active. Only two pins fighting over one id in custom.tlk.yml is now an error. This self-heals on the next build without deleting the state file. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2449,6 +2449,55 @@ strings:
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildStandaloneTLKPinEvictsStaleStateOwner(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "feat"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "tlk"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "feat", "base.json"), `{
|
||||
"output": "feat.2da",
|
||||
"columns": ["LABEL", "FEAT", "DESCRIPTION"],
|
||||
"rows": [{
|
||||
"id": 0,
|
||||
"key": "feat:test",
|
||||
"LABEL": "TEST_LABEL",
|
||||
"FEAT": {"tlk": {"key": "feat:test.name", "text": "Test Feat"}},
|
||||
"DESCRIPTION": "****"
|
||||
}]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "tlk", "custom.tlk.yml"), `schema: sow-topdata/tlk/v1
|
||||
base_strref: 16777216
|
||||
strings:
|
||||
- key: sow.module.name
|
||||
text: Shadows Over Westgate
|
||||
id: 50
|
||||
`)
|
||||
// Simulate a per-machine state that predates the pinned taxonomy: the feat
|
||||
// ref dynamically grabbed id 50 on an older build, exactly where the pin
|
||||
// now lives. The build must self-heal instead of failing.
|
||||
writeFile(t, filepath.Join(root, "topdata", tlkStateFile),
|
||||
`{"version":1,"language":"en","entries":{"feat:test.name":{"id":50}}}`+"\n")
|
||||
|
||||
if _, err := BuildNative(testProject(root), nil); err != nil {
|
||||
t.Fatalf("BuildNative failed on stale pin collision: %v", err)
|
||||
}
|
||||
|
||||
stateRaw, err := os.ReadFile(filepath.Join(root, "topdata", tlkStateFile))
|
||||
if err != nil {
|
||||
t.Fatalf("read tlk state: %v", err)
|
||||
}
|
||||
var state tlkStateDocument
|
||||
if err := json.Unmarshal(stateRaw, &state); err != nil {
|
||||
t.Fatalf("parse tlk state: %v", err)
|
||||
}
|
||||
if state.Entries["sow.module.name"].ID != 50 {
|
||||
t.Fatalf("pin must own id 50, got %#v", state.Entries["sow.module.name"])
|
||||
}
|
||||
if got := state.Entries["feat:test.name"].ID; got == 50 {
|
||||
t.Fatalf("stale feat ref should have been reallocated off id 50, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPreservesTLKStateAcrossTextChanges(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "skills"))
|
||||
|
||||
Reference in New Issue
Block a user