@snaptrude/plugin-core 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/api-manifest.json +206 -704
  3. package/dist/api/core/index.d.ts +5 -0
  4. package/dist/api/core/index.d.ts.map +1 -1
  5. package/dist/api/core/proposals/index.d.ts +475 -0
  6. package/dist/api/core/proposals/index.d.ts.map +1 -0
  7. package/dist/api/design/create/index.d.ts +209 -0
  8. package/dist/api/design/create/index.d.ts.map +1 -1
  9. package/dist/api/design/doors/index.d.ts +159 -0
  10. package/dist/api/design/doors/index.d.ts.map +1 -1
  11. package/dist/api/design/furniture/index.d.ts +34 -5
  12. package/dist/api/design/furniture/index.d.ts.map +1 -1
  13. package/dist/api/design/index.d.ts +83 -0
  14. package/dist/api/design/index.d.ts.map +1 -1
  15. package/dist/api/design/lock.d.ts +26 -0
  16. package/dist/api/design/lock.d.ts.map +1 -1
  17. package/dist/api/design/materials/index.d.ts +159 -2
  18. package/dist/api/design/materials/index.d.ts.map +1 -1
  19. package/dist/api/design/query/index.d.ts +115 -5
  20. package/dist/api/design/query/index.d.ts.map +1 -1
  21. package/dist/api/design/selection/index.d.ts +2 -2
  22. package/dist/api/design/transform/index.d.ts +83 -2
  23. package/dist/api/design/transform/index.d.ts.map +1 -1
  24. package/dist/api/design/update/index.d.ts +168 -0
  25. package/dist/api/design/update/index.d.ts.map +1 -1
  26. package/dist/api/design/windows/index.d.ts +113 -2
  27. package/dist/api/design/windows/index.d.ts.map +1 -1
  28. package/dist/api/entity/story.d.ts +101 -7
  29. package/dist/api/entity/story.d.ts.map +1 -1
  30. package/dist/api/presentation/aiInspiration.d.ts +1967 -7
  31. package/dist/api/presentation/aiInspiration.d.ts.map +1 -1
  32. package/dist/api/presentation/import.d.ts +49 -4
  33. package/dist/api/presentation/import.d.ts.map +1 -1
  34. package/dist/api/presentation/index.d.ts +2 -3
  35. package/dist/api/presentation/index.d.ts.map +1 -1
  36. package/dist/api/presentation/views.d.ts +210 -5
  37. package/dist/api/presentation/views.d.ts.map +1 -1
  38. package/dist/api/program/areas.d.ts +42 -12
  39. package/dist/api/program/areas.d.ts.map +1 -1
  40. package/dist/api/program/index.d.ts +3 -11
  41. package/dist/api/program/index.d.ts.map +1 -1
  42. package/dist/api/program/layout.d.ts +186 -11
  43. package/dist/api/program/layout.d.ts.map +1 -1
  44. package/dist/errors/codes.d.ts +34 -0
  45. package/dist/errors/codes.d.ts.map +1 -0
  46. package/dist/errors/envelope.d.ts +56 -0
  47. package/dist/errors/envelope.d.ts.map +1 -0
  48. package/dist/errors/index.d.ts +6 -0
  49. package/dist/errors/index.d.ts.map +1 -0
  50. package/dist/errors/plugin-error.d.ts +69 -0
  51. package/dist/errors/plugin-error.d.ts.map +1 -0
  52. package/dist/host-utils.d.ts +4 -0
  53. package/dist/host-utils.d.ts.map +1 -1
  54. package/dist/index.cjs +1993 -1033
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.ts +1 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +1874 -1030
  59. package/dist/index.js.map +1 -1
  60. package/package.json +2 -1
  61. package/scripts/generate-manifest.test.mjs +77 -0
  62. package/src/api/core/index.ts +5 -0
  63. package/src/api/core/proposals/index.ts +509 -0
  64. package/src/api/design/create/index.ts +249 -0
  65. package/src/api/design/doors/index.ts +168 -0
  66. package/src/api/design/furniture/index.ts +36 -5
  67. package/src/api/design/index.ts +87 -0
  68. package/src/api/design/lock.ts +27 -0
  69. package/src/api/design/materials/index.ts +182 -2
  70. package/src/api/design/query/index.ts +81 -0
  71. package/src/api/design/transform/index.ts +74 -2
  72. package/src/api/design/update/index.ts +167 -0
  73. package/src/api/design/windows/index.ts +128 -2
  74. package/src/api/entity/story.ts +105 -7
  75. package/src/api/presentation/aiInspiration.ts +761 -7
  76. package/src/api/presentation/import.ts +45 -4
  77. package/src/api/presentation/index.ts +2 -3
  78. package/src/api/presentation/views.ts +221 -5
  79. package/src/api/program/areas.ts +34 -12
  80. package/src/api/program/index.ts +3 -11
  81. package/src/api/program/layout.ts +195 -11
  82. package/src/errors/codes.ts +136 -0
  83. package/src/errors/envelope.ts +75 -0
  84. package/src/errors/index.ts +21 -0
  85. package/src/errors/plugin-error.ts +134 -0
  86. package/src/host-utils.ts +4 -0
  87. package/src/index.ts +1 -0
  88. package/test/errors.test.mjs +184 -0
  89. package/api-manifest.full.json +0 -5600
@@ -0,0 +1,184 @@
1
+ // Node built-in test runner suite for the error module (codes/envelope/PluginError).
2
+ // Run: node --test test/
3
+ // Imports the BUILT package (dist) — run `pnpm build` first.
4
+ import test from "node:test"
5
+ import assert from "node:assert/strict"
6
+ import {
7
+ PLUGIN_ERROR_CODES,
8
+ CODE_META,
9
+ isPluginErrorCode,
10
+ ERROR_ENVELOPE_VERSION,
11
+ isErrorEnvelope,
12
+ newErrorId,
13
+ PluginError,
14
+ PluginValidationError,
15
+ PluginQuotaError,
16
+ PluginTimeoutError,
17
+ PluginTransportError,
18
+ PluginInternalError,
19
+ fromEnvelope,
20
+ makeClientEnvelope,
21
+ } from "../dist/index.js"
22
+
23
+ const CATEGORIES = [
24
+ "validation", "not_found", "permission", "handle", "quota",
25
+ "timeout", "transport", "lifecycle", "execution", "internal",
26
+ ]
27
+
28
+ function envelope(overrides = {}) {
29
+ return {
30
+ envelopeVersion: ERROR_ENVELOPE_VERSION,
31
+ code: "OPERATION_FAILED",
32
+ message: "it failed",
33
+ errorId: "test-id-1",
34
+ ...overrides,
35
+ }
36
+ }
37
+
38
+ // --- codes registry ---------------------------------------------------------
39
+
40
+ test("every code has CODE_META with a valid category (union↔meta completeness)", () => {
41
+ for (const code of PLUGIN_ERROR_CODES) {
42
+ const meta = CODE_META[code]
43
+ assert.ok(meta, `missing CODE_META for ${code}`)
44
+ assert.ok(CATEGORIES.includes(meta.category), `bad category for ${code}: ${meta.category}`)
45
+ }
46
+ assert.equal(Object.keys(CODE_META).length, PLUGIN_ERROR_CODES.length)
47
+ })
48
+
49
+ test("codes are unique", () => {
50
+ assert.equal(new Set(PLUGIN_ERROR_CODES).size, PLUGIN_ERROR_CODES.length)
51
+ })
52
+
53
+ test("isPluginErrorCode narrows union members and rejects strangers", () => {
54
+ assert.equal(isPluginErrorCode("HANDLE_INVALID"), true)
55
+ assert.equal(isPluginErrorCode("TOTALLY_MADE_UP"), false)
56
+ assert.equal(isPluginErrorCode(""), false)
57
+ })
58
+
59
+ // --- envelope ----------------------------------------------------------------
60
+
61
+ test("isErrorEnvelope accepts a minimal valid envelope", () => {
62
+ assert.equal(isErrorEnvelope(envelope()), true)
63
+ })
64
+
65
+ test("isErrorEnvelope accepts codes OUTSIDE the union (forward compat)", () => {
66
+ assert.equal(isErrorEnvelope(envelope({ code: "FUTURE_CODE" })), true)
67
+ })
68
+
69
+ test("isErrorEnvelope rejects malformed values", () => {
70
+ assert.equal(isErrorEnvelope(null), false)
71
+ assert.equal(isErrorEnvelope("boom"), false)
72
+ assert.equal(isErrorEnvelope({}), false)
73
+ assert.equal(isErrorEnvelope(envelope({ envelopeVersion: 2 })), false)
74
+ assert.equal(isErrorEnvelope(envelope({ errorId: undefined })), false)
75
+ })
76
+
77
+ test("newErrorId returns unique prefixed ids", () => {
78
+ const a = newErrorId("c-")
79
+ const b = newErrorId("c-")
80
+ assert.notEqual(a, b)
81
+ assert.ok(a.startsWith("c-"))
82
+ })
83
+
84
+ // --- PluginError rehydration --------------------------------------------------
85
+
86
+ test("fromEnvelope picks the category sugar subclass", () => {
87
+ assert.ok(fromEnvelope(envelope({ code: "VALIDATION" })) instanceof PluginValidationError)
88
+ assert.ok(fromEnvelope(envelope({ code: "RATE_LIMITED" })) instanceof PluginQuotaError)
89
+ assert.ok(fromEnvelope(envelope({ code: "TIMEOUT" })) instanceof PluginTimeoutError)
90
+ assert.ok(fromEnvelope(envelope({ code: "TRANSPORT_LOST" })) instanceof PluginTransportError)
91
+ assert.ok(fromEnvelope(envelope({ code: "INTERNAL" })) instanceof PluginInternalError)
92
+ })
93
+
94
+ test("fromEnvelope preserves envelope fields on the error", () => {
95
+ const err = fromEnvelope(
96
+ envelope({
97
+ code: "OPERATION_FAILED",
98
+ details: { op: "union", handles: ["mass_1", "mass_2"] },
99
+ handle: "mass_1",
100
+ methodPath: "design.boolean.union",
101
+ hint: "check overlap",
102
+ })
103
+ )
104
+ assert.equal(err.code, "OPERATION_FAILED")
105
+ assert.equal(err.message, "it failed")
106
+ assert.equal(err.errorId, "test-id-1")
107
+ assert.deepEqual(err.details, { op: "union", handles: ["mass_1", "mass_2"] })
108
+ assert.equal(err.handle, "mass_1")
109
+ assert.equal(err.methodPath, "design.boolean.union")
110
+ assert.equal(err.hint, "check overlap")
111
+ assert.equal(err.category, "execution")
112
+ })
113
+
114
+ test("unknown code constructs base PluginError with code preserved verbatim", () => {
115
+ const err = fromEnvelope(envelope({ code: "FUTURE_CODE" }))
116
+ assert.equal(err.constructor, PluginError)
117
+ assert.equal(err.code, "FUTURE_CODE")
118
+ assert.equal(err.category, "internal")
119
+ assert.equal(PluginError.is(err), true)
120
+ })
121
+
122
+ test("hint falls back to the code's template when the envelope has none", () => {
123
+ const err = fromEnvelope(envelope({ code: "RATE_LIMITED" }))
124
+ assert.equal(err.hint, CODE_META.RATE_LIMITED.hintTemplate)
125
+ })
126
+
127
+ test("PluginError.is matches the brand across class identities (dual SDK copy)", () => {
128
+ // Simulate a second bundled copy: a plain object carrying the Symbol.for
129
+ // brand but NOT part of this module's prototype chain.
130
+ const impostor = Object.assign(new Error("from other copy"), {
131
+ [Symbol.for("snaptrude.pluginError")]: true,
132
+ code: "TIMEOUT",
133
+ })
134
+ assert.equal(impostor instanceof PluginError, false)
135
+ assert.equal(PluginError.is(impostor), true)
136
+ assert.equal(PluginError.is(new Error("plain")), false)
137
+ assert.equal(PluginError.is(null), false)
138
+ })
139
+
140
+ // --- makeClientEnvelope --------------------------------------------------------
141
+
142
+ test("makeClientEnvelope mints a c- prefixed id and passes extras through", () => {
143
+ const env = makeClientEnvelope("TRANSPORT_LOST", "port closed", {
144
+ methodPath: "design.boolean.union",
145
+ })
146
+ assert.equal(isErrorEnvelope(env), true)
147
+ assert.equal(env.code, "TRANSPORT_LOST")
148
+ assert.ok(env.errorId.startsWith("c-"))
149
+ assert.equal(env.methodPath, "design.boolean.union")
150
+ })
151
+
152
+ // --- Registry snapshot (append-only guard) -----------------------------------
153
+ // Deliberate: adding a code REQUIRES updating this list in the same change so
154
+ // the addition is reviewed; removing or renaming one must fail loudly forever.
155
+
156
+ test("PLUGIN_ERROR_CODES matches the reviewed snapshot (append-only contract)", () => {
157
+ assert.deepEqual([...PLUGIN_ERROR_CODES], [
158
+ "VALIDATION",
159
+ "INVALID_RPC_FORMAT",
160
+ "METHOD_NOT_FOUND",
161
+ "METHOD_NOT_PERMITTED",
162
+ "HANDLE_INVALID",
163
+ "HANDLE_KIND_MISMATCH",
164
+ "RESOURCE_QUOTA_EXCEEDED",
165
+ "RATE_LIMITED",
166
+ "PRECONDITION_FAILED",
167
+ "OPERATION_FAILED",
168
+ "TIMEOUT",
169
+ "CALL_TIMEOUT",
170
+ "TRANSPORT_LOST",
171
+ "PLUGIN_NOT_READY",
172
+ "PLUGIN_TERMINATED",
173
+ "RESULT_NOT_SERIALIZABLE",
174
+ "RESULT_TOO_LARGE",
175
+ "BATCH_PARTIAL",
176
+ "STORY_UPDATE_FAILED",
177
+ "STORY_HEIGHT_REJECTED",
178
+ "NO_ACTIVE_STRUCTURE",
179
+ "NO_ELIGIBLE_ELEMENTS",
180
+ "PROPOSAL_SWITCH_BLOCKED",
181
+ "INTERNAL",
182
+ "UNKNOWN",
183
+ ])
184
+ })