nx_dms_catalog_gate.nx source
↩ module page · 68 lines · 3402 B
1// nx_dms_catalog_gate.nx -- liar-kill gate for the consent-gated catalog.
2//
3// The point: media surfaces ONLY when its (talent, use) is currently
4// licensed. Proven by construction --
5// unlicensed talent's asset -> NOT visible
6// license REVOKED -> its asset stops surfacing instantly
7// license EXPIRED -> same
8// soft-removed asset -> NOT visible (even if licensed)
9// unknown asset -> NOT visible
10// licensed + active -> visible
11// plus content-addressed idempotent add and additive (history-kept) removal.
12// Returns 0 iff every check holds; a nonzero code pinpoints the first failure.
13
14import "nx_syscalls.nx"
15import "nx_rights_ledger.nx"
16import "nx_dms_catalog.nx"
17
18func main() -> i64 {
19 let l: *NxRightsLedger = nx_rights_ledger_new(16)
20 let c: *NxDmsCatalog = nx_dms_catalog_new(16)
21
22 // licenses: 7 grants MERCH + WEB_GALLERY, 9 grants AD (all term 1000..11000)
23 if nx_rights_grant(l, 1, 7, NX_USE_MERCH, 1000, 10000) != NX_RL_OK { return 1 }
24 if nx_rights_grant(l, 2, 7, NX_USE_WEB_GALLERY, 1000, 10000) != NX_RL_OK { return 2 }
25 if nx_rights_grant(l, 3, 9, NX_USE_AD_CAMPAIGN, 1000, 10000) != NX_RL_OK { return 3 }
26
27 // catalog assets (content_hash = distinct fingerprints)
28 if nx_dms_catalog_add(c, 101, 7, NX_USE_MERCH, 43690, 1500) != NX_DMS_OK { return 4 }
29 if nx_dms_catalog_add(c, 102, 7, NX_USE_WEB_GALLERY, 48059, 1500) != NX_DMS_OK { return 5 }
30 if nx_dms_catalog_add(c, 103, 9, NX_USE_AD_CAMPAIGN, 52428, 1500) != NX_DMS_OK { return 6 }
31 if nx_dms_catalog_add(c, 104, 8, NX_USE_MERCH, 56797, 1500) != NX_DMS_OK { return 7 } // talent 8 = UNLICENSED
32 if nx_dms_catalog_count(c) != 4 { return 8 }
33
34 // content-addressed idempotent add: same content_hash -> DUP, no growth
35 if nx_dms_catalog_add(c, 199, 7, NX_USE_MERCH, 43690, 1600) != NX_DMS_DUP { return 9 }
36 if nx_dms_catalog_count(c) != 4 { return 10 }
37
38 // bad use refused
39 if nx_dms_catalog_add(c, 200, 7, 99, 12345, 1600) != NX_DMS_ERR_BAD_USE { return 11 }
40
41 // licensed + active -> VISIBLE
42 if nx_dms_is_visible(c, l, 101, 5000) != 1 { return 12 }
43 if nx_dms_is_visible(c, l, 102, 5000) != 1 { return 13 }
44 if nx_dms_is_visible(c, l, 103, 5000) != 1 { return 14 }
45
46 // NEG-CONTROL: asset of an UNLICENSED talent -> NOT visible (by construction)
47 if nx_dms_is_visible(c, l, 104, 5000) != 0 { return 15 }
48 if nx_dms_count_visible(c, l, 5000) != 3 { return 16 }
49
50 // REVOKE the web-gallery license -> asset 102 stops surfacing instantly
51 if nx_rights_revoke(l, 2, 4000) != NX_RL_OK { return 17 }
52 if nx_dms_is_visible(c, l, 102, 5000) != 0 { return 18 }
53 if nx_dms_count_visible(c, l, 5000) != 2 { return 19 }
54
55 // SOFT-REMOVE a licensed asset -> not visible, but the row is kept
56 if nx_dms_catalog_remove(c, 101, 6000) != NX_DMS_OK { return 20 }
57 if nx_dms_is_visible(c, l, 101, 5000) != 0 { return 21 }
58 if nx_dms_catalog_count(c) != 4 { return 22 } // history sacred: still 4 rows
59 if nx_dms_count_visible(c, l, 5000) != 1 { return 23 } // only 103 remains
60
61 // unknown asset -> not visible
62 if nx_dms_is_visible(c, l, 999, 5000) != 0 { return 24 }
63
64 // EXPIRY propagates: query past the term -> 103 no longer visible (LAST)
65 if nx_dms_is_visible(c, l, 103, 99999) != 0 { return 25 }
66
67 return 0
68}