File size: 2,083 Bytes
e379257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Gold fix (Yu, 2026-10-24): a destructive row inside the settings list (e.g. Delete Account)

is NOT the primary button. For settings_destructive records whose primary_button gold is that

destructive row, set primary_button -> "none" and box_primary_button -> {"present": false}.

A record keeps its gold if it has a real primary CTA (a primary box distinct from the destructive box

and a non-destructive gold value). has_destructive_action is left untouched.



usage: python scripts/fix_settings_gold.py in.jsonl out.jsonl

"""
import collections, json, sys

DESTRUCTIVE = {"delete", "discard"}


def main(src, dst):
    n = changed = 0
    before, kept = collections.Counter(), collections.Counter()
    with open(src, encoding="utf-8") as f, open(dst, "w", encoding="utf-8", newline="\n") as out:
        for line in f:
            if not line.strip():
                continue
            r = json.loads(line)
            n += 1
            if "settings_destructive" in r["id"]:
                g = r["gold"]
                old = g.get("primary_button")
                before[old] += 1
                pb, db = g.get("box_primary_button"), g.get("box_destructive_button")
                same_box = isinstance(pb, dict) and pb.get("present") and pb == db
                if old != "none" and (old in DESTRUCTIVE or same_box):
                    g["primary_button"] = "none"
                    if isinstance(pb, dict):
                        g["box_primary_button"] = {"present": False}
                    r["meta"].setdefault("gold_fixes", []).append(
                        f"primary_button:{old}->none (settings destructive row is not primary, 2026-10-24)")
                    changed += 1
                else:
                    kept[old] += 1
            out.write(json.dumps(r, ensure_ascii=False) + "\n")
    print(f"{n} records, settings_destructive primary_button before={dict(before)}, "
          f"changed->none={changed}, kept={dict(kept)} -> {dst}")


if __name__ == "__main__":
    main(sys.argv[1], sys.argv[2])