RynthChat server tabs: review fixes (pure apply core, pairing, clashes)
The decision core of ChatModel.ApplyServerTab moves into ChatServerTabs.Apply, a pure function returning edits (rule updates, inserts, removals, tab create, pin, seed mark, tab server); ChatModel only carries them out. ChatFilterTests drives it through a small settings model. - A seeded entry whose tab was deleted never gets a rule turned on: a rule the manifest gains, or one re-added after the player deleted the rules, is added off. Tab listing skips a tab only an inactive server's rule fills. - Owned rules pair with declared ones by content (Global-room flag, then when/action/mode/pattern, then leftovers), never by position, so a reorder or delete no longer moves on/off or colour to another rule. Reclaim uses the same pairing. - Settings count as ready only after a successful read (or no file); a failed read is retried every 2 s, the unreadable copy kept once. - Export leaves out server rules and server tabs; Import makes every imported rule the player's (no owner, server or globalRoom). - Both rule editors lock pattern, mode, when, action, tab, move and delete on a server rule; on/off and colour stay live, with a note. - No adopt-by-name: a taken name seeds "<Name> (<server name>)" instead, and tabServers is written only for a tab the plugin made. Reclaim requires the entry's name, its clash name, or a tab holding only the matched rules. AddCustomTab checks hidden tabs. - Global-room discovery re-reads the entries and active servers under the lock. The manifest parser rejects a bad when or mode, and keeps a pattern's spaces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
01f432d745
commit
05a6d7d088
8 changed files with 717 additions and 281 deletions
|
|
@ -616,6 +616,19 @@ internal static class Program
|
|||
var noFallback = SectionManifestParser.Parse("DW", """{ "chatTabs": [ { "server": "dw", "id": "a", "name": "A", "rules": [] } ] }""", out _);
|
||||
Check(noFallback.ChatTabs.Length == 1 && noFallback.ChatTabs[0].GlobalRoomFallback == "Roleplay", "absent globalRoomFallback = Roleplay");
|
||||
|
||||
Case("manifest: chatTabs rule when, mode and pattern are kept as written");
|
||||
m = SectionManifestParser.Parse("DW", """
|
||||
{ "chatTabs": [ { "server": "dw", "id": "a", "name": "A", "rules": [
|
||||
{ "action": "copy", "when": "chan:Combat", "mode": "StartsWith", "pattern": "[Trade] " },
|
||||
{ "action": "copy", "when": "TYPE:4", "mode": "contains", "pattern": " two " },
|
||||
{ "action": "copy", "when": "", "mode": "startswith", "pattern": "ignored", "globalRoom": true } ] } ] }
|
||||
""", out err);
|
||||
Check(err.Length == 0 && m.ChatTabs.Length == 1 && m.ChatTabs[0].Rules.Length == 3, "three valid rules parse: " + err);
|
||||
SectionChatRuleDecl[] kept = m.ChatTabs.Length == 1 ? m.ChatTabs[0].Rules : System.Array.Empty<SectionChatRuleDecl>();
|
||||
Check(kept.Length == 3 && kept[0].Pattern == "[Trade] " && kept[1].Pattern == " two ", "a pattern's spaces are kept");
|
||||
Check(kept.Length == 3 && kept[0].When == "chan:Combat" && kept[1].When == "TYPE:4" && kept[0].Mode == "startswith", "chan:/type: when accepted, mode lower-cased");
|
||||
Check(kept.Length == 3 && kept[2].Pattern == "", "a globalRoom rule's pattern is ignored (the engine supplies it)");
|
||||
|
||||
// Each reject drops the entry, reports it in error, and still parses the other keys.
|
||||
string section = """ "sections": [ { "id": "quests", "label": "Quests", "order": 150 } ] """;
|
||||
string[] bad =
|
||||
|
|
@ -625,8 +638,14 @@ internal static class Program
|
|||
"""{ "server": "dw", "id": "Bad Id", "name": "A", "globalRoomFallback": "General", "rules": [] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "globalRoomFallback": "General", "rules": [ { "action": "delete", "when": "", "mode": "", "pattern": "x" } ] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "globalRoomFallback": "Sports", "rules": [] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "rules": [ { "action": "copy", "when": "typo:3", "mode": "", "pattern": "x" } ] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "rules": [ { "action": "copy", "when": "type:x", "mode": "", "pattern": "x" } ] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "rules": [ { "action": "copy", "when": "type:-1", "mode": "", "pattern": "x" } ] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "rules": [ { "action": "copy", "when": "chan:", "mode": "", "pattern": "x" } ] }""",
|
||||
"""{ "server": "dw", "id": "a", "name": "A", "rules": [ { "action": "copy", "when": "", "mode": "startwith", "pattern": "x" } ] }""",
|
||||
};
|
||||
string[] why = { "missing server", "missing id", "bad id", "bad action", "bad fallback" };
|
||||
string[] why = { "missing server", "missing id", "bad id", "bad action", "bad fallback",
|
||||
"when typo:3", "when type:x", "when type:-1", "when chan: with no tab", "mode startwith" };
|
||||
for (int i = 0; i < bad.Length; i++)
|
||||
{
|
||||
m = SectionManifestParser.Parse("DW", "{ " + section + ", \"chatTabs\": [" + bad[i] + "] }", out err);
|
||||
|
|
|
|||
Loading…
Reference in a new issue