Repository navigation
Expand file tree
/
Copy pathpackage-api.test.ts
More file actions
1303 lines (1173 loc) · 59.5 KB
/
Copy pathpackage-api.test.ts
File metadata and controls
1303 lines (1173 loc) · 59.5 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { describe, it, expect } from 'vitest';
import {
PackagePathParamsSchema,
ListInstalledPackagesRequestSchema,
GetInstalledPackageRequestSchema,
PackageInstallRequestSchema,
PackageInstallBodySchema,
PackageInstallManifestSchema,
PackageInstallResponseSchema,
PackageUpgradeRequestSchema,
PackageUpgradeResponseSchema,
ResolveDependenciesRequestSchema,
ResolveDependenciesResponseSchema,
UploadArtifactRequestSchema,
UploadArtifactResponseSchema,
PackageRollbackRequestSchema,
UninstallPackageApiRequestSchema,
UninstallPackageApiResponseSchema,
PackageApiErrorCode,
} from './package-api.zod';
// The declarations that embed the assembled package body live one file over
// and ship from `@objectstack/spec/api-assembled` (#18576 ruling, letter B).
import {
ListInstalledPackagesResponseSchema,
GetInstalledPackageResponseSchema,
PackageApiContracts,
AssembledInstalledPackageSchema,
InstalledPackageAtEitherStageSchema,
} from './package-api-assembled.zod';
import { InstalledPackageSchema } from '../kernel/package-registry.zod';
import { ManifestSchema } from '../kernel/manifest.zod';
import { AssembledPackageBodySchema } from '../stack.zod';
import { z } from 'zod';
// ==========================================
// Path Parameters
// ==========================================
describe('PackagePathParamsSchema', () => {
it('should accept a valid package ID', () => {
const result = PackagePathParamsSchema.parse({ packageId: 'com.acme.crm' });
expect(result.packageId).toBe('com.acme.crm');
});
});
// ==========================================
// List Packages
// ==========================================
describe('ListInstalledPackagesRequestSchema', () => {
// [#17667] These two cases used to pin `limit`'s `.default(50)` and a
// round-tripped `cursor`. They are REPLACED rather than respelled: they
// pinned exactly the branch route 2 deleted, so keeping them in any form
// would have meant re-asserting a contract that no longer exists.
it('accepts a minimal request and materializes no window', () => {
const result = ListInstalledPackagesRequestSchema.parse({});
expect(result.status).toBeUndefined();
expect(result.enabled).toBeUndefined();
expect(result.type).toBeUndefined();
// ⭐ There is no default to apply any more: the door has never capped this
// list, so an omitted request declares no window rather than a fictional
// 50-row one.
expect(result).not.toHaveProperty('limit');
});
it('accepts every filter the serving door actually executes', () => {
const result = ListInstalledPackagesRequestSchema.parse({
status: 'installed',
enabled: true,
type: 'app',
});
expect(result.status).toBe('installed');
expect(result.enabled).toBe(true);
expect(result.type).toBe('app');
});
it('should reject invalid status', () => {
expect(() => ListInstalledPackagesRequestSchema.parse({ status: 'running' })).toThrow();
});
// ── #17667 retirement pins: the prescription, and the absence ────────────
//
// The NEGATIVE half. A bare `.toThrow()` would be satisfied by any refusal,
// including the generic unrecognized-key issue a plain deletion produces —
// which is exactly the silent-ish failure the tombstone exists to replace.
// So the assertion is the prescription text itself. The `s` flag is house
// style: the message is one long string and matchers span its clauses.
it.each(['limit', 'cursor'])('refuses a retired `%s` with the prescription, not a bare unknown key', (key) => {
const result = ListInstalledPackagesRequestSchema.safeParse({ [key]: key === 'limit' ? 20 : 'abc123' });
expect(result.success).toBe(false);
const issue = result.error!.issues.find((i) => i.path.join('.') === key);
expect(issue, `must fault on the \`${key}\` path`).toBeDefined();
expect(issue!.message).toMatch(/`limit` \/ `cursor` were removed from GET \/api\/v1\/packages/s);
expect(issue!.message).toMatch(/removed .*in @objectstack\/spec 17\.5\.0 \(ADR-0049 enforce-or-remove\)/s);
// The `.default(50)` is named specifically — a reader who trusted the cap
// is the consumer this retirement owes an explanation to.
expect(issue!.message).toMatch(/`\.default\(50\)`/s);
expect(issue!.message).toMatch(/Delete the key\./s);
});
// The POSITIVE half. Absence still parses — the retirement removed a
// declaration, not the ability to call the route without one.
it('parses clean when neither retired key is sent', () => {
const result = ListInstalledPackagesRequestSchema.safeParse({ status: 'installed' });
expect(result.success).toBe(true);
expect(result.data).not.toHaveProperty('cursor');
});
// [#17667] `hasMore` is a constant `false` that is now true BY CONSTRUCTION:
// with no request-side way to ask for a page, there can be no next one. This
// pins the response half against a future author "fixing" the constant back
// into a computed value without restoring a way to ask.
it('declares a response that can honestly report one page', () => {
const parsed = ListInstalledPackagesResponseSchema.parse({
success: true,
data: { packages: [], total: 0, hasMore: false },
});
expect(parsed.data.hasMore).toBe(false);
expect(parsed.data).not.toHaveProperty('nextCursor');
});
});
// ==========================================
// [#17667] Executed-but-undeclared query parameters, now declared
// ==========================================
describe('the /packages doors declare the query parameters they execute', () => {
it('GET /packages/:id declares the `?version=` scope it honours', () => {
const parsed = GetInstalledPackageRequestSchema.parse({ packageId: 'com.acme.crm', version: '1.2.3' });
expect(parsed.packageId).toBe('com.acme.crm');
expect(parsed.version).toBe('1.2.3');
// `latest` is a literal the door treats as "the installed row" — it is a
// plain string here, deliberately NOT a dist-tag or semver-range grammar.
expect(GetInstalledPackageRequestSchema.parse({ packageId: 'p', version: 'latest' }).version).toBe('latest');
// Omitted stays omitted: the by-id read is unscoped without it.
expect(GetInstalledPackageRequestSchema.parse({ packageId: 'p' }).version).toBeUndefined();
});
it('DELETE /packages/:id declares the `?keepData=` option it honours', () => {
const parsed = UninstallPackageApiRequestSchema.parse({ packageId: 'com.acme.crm', keepData: true });
expect(parsed.packageId).toBe('com.acme.crm');
expect(parsed.keepData).toBe(true);
// Omitted is the destructive default — storage goes with the metadata.
expect(UninstallPackageApiRequestSchema.parse({ packageId: 'p' }).keepData).toBeUndefined();
});
it('binds each declaration to the door that executes it', () => {
// The contract map is what SDKs and codegen read; a declaration that is
// right in the file and unbound in the map is invisible to both.
expect(PackageApiContracts.listPackages.input).toBe(ListInstalledPackagesRequestSchema);
expect(PackageApiContracts.getPackage.input).toBe(GetInstalledPackageRequestSchema);
expect(PackageApiContracts.uninstallPackage.input).toBe(UninstallPackageApiRequestSchema);
});
});
// ==========================================
// Install Package
// ==========================================
describe('PackageInstallRequestSchema', () => {
it('should accept a minimal install request — and leave an absent `enableOnInstall` UNDEFINED', () => {
const result = PackageInstallRequestSchema.parse({
manifest: {
id: 'com.acme.crm',
name: 'acme_crm',
version: '1.0.0',
type: 'plugin',
},
});
// ⭐ [#19273] This assertion read `toBe(true)` while the declaration spelled
// `.default(true)`, and it was the lit control proving absence really was
// erased at parse time. The declaration is `optional()` now — 「缺省 = 保持,
// 有旗 = 设置」 — so the absence survives the parse and the door's three-way
// read has a third state to see. The full matrix, with the flip-trigger it
// was registered under, is in `package-install-one-authority.test.ts`.
expect(result.enableOnInstall).toBeUndefined();
});
it('should accept full install request with platform version', () => {
const result = PackageInstallRequestSchema.parse({
manifest: {
id: 'com.acme.crm',
name: 'acme_crm',
version: '1.0.0',
type: 'plugin',
},
settings: { apiKey: 'abc123' },
enableOnInstall: false,
platformVersion: '3.2.0',
artifactRef: {
url: 'https://marketplace.objectstack.io/artifacts/com.acme.crm/1.0.0.tgz',
sha256: 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2',
size: 1024000,
uploadedAt: '2026-02-01T10:00:00Z',
},
});
expect(result.enableOnInstall).toBe(false);
expect(result.platformVersion).toBe('3.2.0');
expect(result.artifactRef?.sha256).toBeDefined();
});
});
describe('PackageInstallResponseSchema', () => {
// The row `POST /api/v1/packages` answers as `data` — bare, no wrapper. The
// wire half (the real dispatcher's answer parsed with this schema) is pinned
// in `packages/client/src/packages-write-envelope.test.ts`.
const ROW = {
manifest: { id: 'com.acme.crm', name: 'acme_crm', version: '1.0.0', type: 'plugin' },
source: 'authored',
status: 'installed',
enabled: true,
installedAt: '2026-11-05T00:00:00.000Z',
};
it('accepts the installed row itself as data', () => {
const result = PackageInstallResponseSchema.parse({ success: true, data: ROW });
expect(result.success).toBe(true);
expect(result.data.manifest.id).toBe('com.acme.crm');
expect(result.data.source).toBe('authored');
expect(result.data.status).toBe('installed');
expect(result.data.enabled).toBe(true);
});
it('refuses the { package } wrapper no surface sends, at data.manifest and data.source', () => {
const result = PackageInstallResponseSchema.safeParse({
success: true,
data: { package: ROW, message: 'Package installed successfully' },
});
expect(result.success).toBe(false);
const paths = result.error!.issues.map((i) => i.path.join('.'));
expect(paths).toEqual(expect.arrayContaining(['data.manifest', 'data.source']));
});
it('is the output the installPackage contract binds', () => {
expect(PackageApiContracts.installPackage.output).toBe(PackageInstallResponseSchema);
});
});
// ==========================================
// Upgrade Package
// ==========================================
describe('PackageUpgradeRequestSchema', () => {
it('should accept minimal upgrade request', () => {
const result = PackageUpgradeRequestSchema.parse({
packageId: 'com.acme.crm',
});
expect(result.packageId).toBe('com.acme.crm');
expect(result.createSnapshot).toBe(true);
expect(result.mergeStrategy).toBe('three-way-merge');
expect(result.dryRun).toBe(false);
});
it('should accept full upgrade request', () => {
const result = PackageUpgradeRequestSchema.parse({
packageId: 'com.acme.crm',
targetVersion: '2.0.0',
manifest: { id: 'com.acme.crm', name: 'acme_crm', version: '2.0.0', type: 'plugin' },
createSnapshot: true,
mergeStrategy: 'keep-custom',
dryRun: true,
skipValidation: false,
});
expect(result.targetVersion).toBe('2.0.0');
expect(result.mergeStrategy).toBe('keep-custom');
expect(result.dryRun).toBe(true);
});
});
describe('PackageUpgradeResponseSchema', () => {
it('should accept a successful upgrade response', () => {
const result = PackageUpgradeResponseSchema.parse({
success: true,
data: {
success: true,
phase: 'completed',
snapshotId: 'snap_001',
message: 'Upgrade completed successfully',
},
});
expect(result.data.success).toBe(true);
expect(result.data.phase).toBe('completed');
expect(result.data.snapshotId).toBe('snap_001');
});
it('no longer declares `plan` — retired with the upgrade-plan model (#25608), so a stray one is stripped', () => {
const result = PackageUpgradeResponseSchema.parse({
success: true,
data: { success: true, phase: 'completed', plan: { packageId: 'com.acme.crm' } },
});
expect(result.data).not.toHaveProperty('plan');
// Lit control: a declared sibling of the retired key still survives the parse.
expect(result.data.phase).toBe('completed');
});
it('should accept upgrade response with merge conflicts', () => {
const result = PackageUpgradeResponseSchema.parse({
success: true,
data: {
success: false,
phase: 'failed',
conflicts: [{
path: 'objects/account/fields/status',
baseValue: 'active',
incomingValue: 'enabled',
customValue: 'custom_active',
}],
errorMessage: 'Merge conflicts detected',
},
});
expect(result.data.success).toBe(false);
expect(result.data.conflicts).toHaveLength(1);
});
});
// ==========================================
// Resolve Dependencies
// ==========================================
describe('ResolveDependenciesRequestSchema', () => {
it('should accept a resolve request with manifest', () => {
const result = ResolveDependenciesRequestSchema.parse({
manifest: { id: 'com.acme.crm', name: 'acme_crm', version: '1.0.0', type: 'plugin' },
platformVersion: '3.2.0',
});
expect(result.platformVersion).toBe('3.2.0');
});
});
describe('ResolveDependenciesResponseSchema', () => {
it('should accept a resolution response', () => {
const result = ResolveDependenciesResponseSchema.parse({
success: true,
data: {
dependencies: [
{ packageId: 'com.acme.core', requiredRange: '^2.0.0', resolvedVersion: '2.1.0', status: 'satisfied' },
{ packageId: 'com.acme.ui', requiredRange: '^1.5.0', resolvedVersion: '1.5.2', status: 'needs_install' },
],
canProceed: true,
requiredActions: [
{ type: 'install', packageId: 'com.acme.ui', description: 'Install com.acme.ui@1.5.2' },
],
installOrder: ['com.acme.core', 'com.acme.ui', 'com.acme.crm'],
},
});
expect(result.data.canProceed).toBe(true);
expect(result.data.dependencies).toHaveLength(2);
expect(result.data.installOrder).toHaveLength(3);
});
it('should accept resolution with circular dependencies', () => {
const result = ResolveDependenciesResponseSchema.parse({
success: true,
data: {
dependencies: [
{ packageId: 'A', requiredRange: '^1.0.0', status: 'conflict', conflictReason: 'Circular dependency' },
],
canProceed: false,
requiredActions: [
{ type: 'confirm_conflict', packageId: 'A', description: 'Circular dependency detected' },
],
installOrder: [],
circularDependencies: [['A', 'B', 'A']],
},
});
expect(result.data.canProceed).toBe(false);
expect(result.data.circularDependencies).toHaveLength(1);
});
});
// ==========================================
// Upload Artifact
// ==========================================
describe('UploadArtifactRequestSchema', () => {
it('should accept a valid upload request', () => {
const result = UploadArtifactRequestSchema.parse({
artifact: {
packageId: 'com.acme.crm',
version: '1.0.0',
builtAt: '2026-02-01T10:00:00Z',
},
sha256: 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2',
releaseNotes: 'Initial release',
});
expect(result.artifact.packageId).toBe('com.acme.crm');
});
it('should reject invalid SHA256', () => {
expect(() => UploadArtifactRequestSchema.parse({
artifact: { packageId: 'test', version: '1.0.0', builtAt: '2026-02-01T10:00:00Z' },
sha256: 'invalid-hash',
})).toThrow();
});
});
describe('UploadArtifactResponseSchema', () => {
it('should accept a successful upload response', () => {
const result = UploadArtifactResponseSchema.parse({
success: true,
data: {
success: true,
artifactRef: {
url: 'https://marketplace.objectstack.io/artifacts/com.acme.crm/1.0.0.tgz',
sha256: 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2',
size: 1024000,
uploadedAt: '2026-02-01T10:00:00Z',
},
submissionId: 'sub_001',
message: 'Artifact uploaded successfully',
},
});
expect(result.data.success).toBe(true);
expect(result.data.artifactRef?.sha256).toBeDefined();
expect(result.data.submissionId).toBe('sub_001');
});
});
// ==========================================
// Rollback Package
// ==========================================
describe('PackageRollbackRequestSchema', () => {
it('should accept a rollback request', () => {
const result = PackageRollbackRequestSchema.parse({
packageId: 'com.acme.crm',
snapshotId: 'snap_001',
rollbackCustomizations: true,
});
expect(result.packageId).toBe('com.acme.crm');
expect(result.snapshotId).toBe('snap_001');
});
it('should default rollbackCustomizations to true', () => {
const result = PackageRollbackRequestSchema.parse({
packageId: 'com.acme.crm',
snapshotId: 'snap_001',
});
expect(result.rollbackCustomizations).toBe(true);
});
});
// `PackageRollbackResponseSchema` is RETIRED (#12038 3A) — it declared a
// VERSION rollback against the live COMMIT-rollback route. Its retirement pin
// (runtime namespace probes, the registry-retirement.test.ts pattern) lives in
// the `package-rollback-response retirement` block at the end of this file;
// the live route's true contract is covered in package-lifecycle.test.ts.
// ==========================================
// Uninstall Package
// ==========================================
describe('UninstallPackageApiResponseSchema', () => {
it('should accept a successful uninstall response', () => {
const result = UninstallPackageApiResponseSchema.parse({
success: true,
data: {
packageId: 'com.acme.crm',
success: true,
message: 'Package uninstalled',
},
});
expect(result.data.success).toBe(true);
expect(result.data.packageId).toBe('com.acme.crm');
});
});
// ==========================================
// Error Codes
// ==========================================
describe('PackageApiErrorCode', () => {
it('should accept all valid error codes', () => {
const validCodes = [
'package_not_found', 'package_already_installed', 'version_not_found',
'dependency_conflict', 'namespace_conflict', 'platform_incompatible',
'artifact_invalid', 'checksum_mismatch', 'signature_invalid',
'upgrade_failed', 'rollback_failed', 'snapshot_not_found', 'upload_failed',
];
validCodes.forEach(code => {
expect(PackageApiErrorCode.parse(code)).toBe(code);
});
});
it('should reject invalid error code', () => {
expect(() => PackageApiErrorCode.parse('unknown_error')).toThrow();
});
});
// ==========================================
// API Contract Registry
// ==========================================
describe('PackageApiContracts', () => {
it('should have all required endpoints', () => {
expect(PackageApiContracts.listPackages).toBeDefined();
expect(PackageApiContracts.getPackage).toBeDefined();
expect(PackageApiContracts.installPackage).toBeDefined();
expect(PackageApiContracts.uninstallPackage).toBeDefined();
});
it('should have correct HTTP methods', () => {
expect(PackageApiContracts.listPackages.method).toBe('GET');
expect(PackageApiContracts.getPackage.method).toBe('GET');
expect(PackageApiContracts.installPackage.method).toBe('POST');
expect(PackageApiContracts.uninstallPackage.method).toBe('DELETE');
});
it('should have correct paths', () => {
expect(PackageApiContracts.listPackages.path).toBe('/api/v1/packages');
expect(PackageApiContracts.getPackage.path).toBe('/api/v1/packages/:packageId');
// [#18058] REBOUND, not relaxed: this used to pin
// `/api/v1/packages/install`, a path the composed runtime mounts nowhere.
// It now pins the door that serves — a bare `POST /api/v1/packages`,
// distinguished from `listPackages` by method, not by path.
expect(PackageApiContracts.installPackage.path).toBe('/api/v1/packages');
expect(PackageApiContracts.installPackage.path).not.toContain('install');
expect(PackageApiContracts.uninstallPackage.path).toBe('/api/v1/packages/:packageId');
});
it('should have input and output schemas on all contracts', () => {
Object.values(PackageApiContracts).forEach(contract => {
expect(contract.input).toBeDefined();
expect(contract.output).toBeDefined();
expect(contract.method).toBeDefined();
expect(contract.path).toBeDefined();
});
});
});
// ==========================================
// Unmounted contract-map entries removed (#19116)
// ==========================================
describe('the three unmounted `PackageApiContracts` entries are removed', () => {
// The paths the removed entries bound. Nothing in the composed runtime
// mounts any of them, and no serving door existed to rebind them onto.
const UNMOUNTED_PATHS = [
'/api/v1/packages/upgrade',
'/api/v1/packages/resolve-dependencies',
'/api/v1/packages/upload',
];
it('no longer carries the `upgradePackage`, `resolveDependencies` or `uploadArtifact` keys', () => {
for (const key of ['upgradePackage', 'resolveDependencies', 'uploadArtifact']) {
expect(Object.prototype.hasOwnProperty.call(PackageApiContracts, key)).toBe(false);
}
});
it('binds no entry, under any key, to one of the three unmounted paths', () => {
// The whole map, so a phantom cannot come back under a different key.
const claimants = Object.entries(PackageApiContracts)
.filter(([, c]) => UNMOUNTED_PATHS.includes(c.path))
.map(([key]) => key);
expect(claimants).toEqual([]);
});
it('keeps exactly the four entries whose doors serve', () => {
// Anti-vacuity for the two absence pins above, and the declare-with-mount
// rule made visible: a new entry lands here only with the mount it names.
expect(Object.keys(PackageApiContracts).sort()).toEqual([
'getPackage',
'installPackage',
'listPackages',
'uninstallPackage',
]);
});
it('leaves the request/response schemas published, bound to no route', async () => {
// The ruling removed the map entries only; the per-route schemas are a
// separate question and still resolve from the namespace.
const ns = (await import('./index')) as unknown as Record<string, unknown>;
for (const name of [
'PackageUpgradeRequestSchema',
'PackageUpgradeResponseSchema',
'ResolveDependenciesRequestSchema',
'ResolveDependenciesResponseSchema',
'UploadArtifactRequestSchema',
'UploadArtifactResponseSchema',
]) {
expect(Object.prototype.hasOwnProperty.call(ns, name)).toBe(true);
}
});
});
// ==========================================
// package-rollback-response retirement (#12038 3A)
// ==========================================
describe('package-rollback-response retirement (ruled: it described the wrong operation on the live path)', () => {
// Runtime namespace probes, the registry-retirement.test.ts pattern: a
// removed export cannot be imported by name (would not compile), so the pin
// asks the namespace object. Anti-vacuity guard: a neighbour that stayed.
it('`PackageRollbackResponseSchema` is no longer exported from `@objectstack/spec/api`', async () => {
const api = await import('./index');
const ns = api as unknown as Record<string, unknown>;
expect(Object.prototype.hasOwnProperty.call(ns, 'PackageRollbackResponseSchema')).toBe(false);
// Anti-vacuity: the sibling that deliberately stayed still resolves.
expect(Object.prototype.hasOwnProperty.call(ns, 'PackageRollbackRequestSchema')).toBe(true);
});
it('`PackageApiContracts` no longer binds any schema to the live commit-rollback path', () => {
const entries = Object.entries(PackageApiContracts) as Array<[string, { path: string }]>;
expect('rollbackPackage' in PackageApiContracts).toBe(false);
// The load-bearing half: no contract-map entry claims the LIVE path the
// dispatcher serves with `rollbackToPackageCommit` (#12038 §5.2 — the
// retired entry bound the version-rollback schema to exactly this path).
const claimants = entries.filter(([, c]) => c.path === '/api/v1/packages/:packageId/rollback');
expect(claimants).toEqual([]);
// Anti-vacuity: the map still carries its surviving entries.
expect(entries.length).toBeGreaterThan(0);
});
});
// ==========================================
// Manifest STAGES on the installed-package row (#17431 / #14242 road B)
// ==========================================
/**
* The two stages, as one row each, differing ONLY in `manifest.objects`.
*
* Everything else is held equal on purpose: what separates them has to be the
* stage, so a failure below can only be about the stage.
*/
// `source` is the record's origin (every row carries one, #23972); `writable`
// and `disableable` are the served row's verdicts, which the record schemas do
// not declare and strip, so one fixture serves both.
const LIFECYCLE = { source: 'code', status: 'installed', enabled: true, writable: false, disableable: false } as const;
const MANIFEST_BASE = {
id: 'com.acme.stage', namespace: 'stage', version: '1.0.0', type: 'app', scope: 'project',
name: 'Stage Fixture',
} as const;
/** AUTHORING: `objects` are GLOB PATTERNS. */
const GLOB_ROW = { ...LIFECYCLE, manifest: { ...MANIFEST_BASE, objects: ['./src/objects/*.object.yml'] } };
/** ASSEMBLED: `objects` are object DEFINITIONS — what `registerApp` iterates. */
const ASSEMBLED_ROW = {
...LIFECYCLE,
manifest: { ...MANIFEST_BASE, objects: [{ name: 'stage_lead', fields: { title: { type: 'text' } } }] },
};
/** NEITHER stage: one array carrying both spellings — road C's shape. */
const MIXED_ROW = {
...LIFECYCLE,
manifest: {
...MANIFEST_BASE,
objects: ['./src/objects/*.object.yml', { name: 'stage_lead', fields: { title: { type: 'text' } } }],
},
};
describe('the two declared manifest stages are DISTINCT, not two names for one shape', () => {
it('`InstalledPackageSchema` is the AUTHORING stage: globs parse, definitions are refused', () => {
expect(InstalledPackageSchema.safeParse(GLOB_ROW).success).toBe(true);
const dark = InstalledPackageSchema.safeParse(ASSEMBLED_ROW);
expect(dark.success).toBe(false);
expect(dark.error!.issues.map((i) => i.path.join('.'))).toEqual(['manifest.objects.0']);
});
it('`AssembledInstalledPackageSchema` is the ASSEMBLED stage: definitions parse, globs are refused', () => {
expect(AssembledInstalledPackageSchema.safeParse(ASSEMBLED_ROW).success).toBe(true);
const dark = AssembledInstalledPackageSchema.safeParse(GLOB_ROW);
expect(dark.success).toBe(false);
expect(dark.error!.issues.map((i) => i.path.join('.'))).toEqual(['manifest.objects.0']);
});
it('⛔ neither stage was WIDENED to reach the other — each still refuses the other exactly', () => {
// The pair above already shows it; this states the proposition #14242 ruled
// on so a future widening of either declaration reddens by name here.
expect(InstalledPackageSchema.safeParse(ASSEMBLED_ROW).success).toBe(false);
expect(AssembledInstalledPackageSchema.safeParse(GLOB_ROW).success).toBe(false);
});
});
// [#23972] The read doors serve the server's writability verdict on every row;
// it is declared on the SERVED row (both stage branches) and on neither record
// schema, because the registry never stores it.
describe('the served installed-package row declares `writable`', () => {
it('requires a boolean `writable` on either stage', () => {
for (const row of [GLOB_ROW, ASSEMBLED_ROW]) {
const { writable: _omitted, ...bare } = row;
const verdict = InstalledPackageAtEitherStageSchema.safeParse(bare);
expect(verdict.success).toBe(false);
expect(InstalledPackageAtEitherStageSchema.safeParse({ ...row, writable: 'yes' }).success).toBe(false);
}
});
it('keeps `writable` and `source` on the parsed served row', () => {
const parsed = InstalledPackageAtEitherStageSchema.parse({ ...GLOB_ROW, source: 'authored', writable: true });
expect(parsed).toMatchObject({ source: 'authored', writable: true });
});
it('is not part of the registry RECORD: the record schemas strip it', () => {
expect(InstalledPackageSchema.parse(GLOB_ROW)).not.toHaveProperty('writable');
expect(AssembledInstalledPackageSchema.parse(ASSEMBLED_ROW)).not.toHaveProperty('writable');
});
});
// [#28318] The disable door's verdict, served beside `writable` and declared the
// same way: on both stage branches of the served row, on neither record schema.
// The two verdicts are independent statements — a module of an installed app is
// `disableable: true` while `writable: false` — so neither is required to follow
// the other.
describe('the served installed-package row declares `disableable`', () => {
it('requires a boolean `disableable` on either stage', () => {
for (const row of [GLOB_ROW, ASSEMBLED_ROW]) {
expect(InstalledPackageAtEitherStageSchema.safeParse(row).success).toBe(true);
const { disableable: _omitted, ...bare } = row;
const verdict = InstalledPackageAtEitherStageSchema.safeParse(bare);
expect(verdict.success).toBe(false);
expect(InstalledPackageAtEitherStageSchema.safeParse({ ...row, disableable: 'yes' }).success).toBe(false);
}
});
it('declares it on BOTH stage branches, beside `writable`', () => {
const branches = InstalledPackageAtEitherStageSchema.options;
expect(branches).toHaveLength(2);
for (const branch of branches) {
expect(Object.keys(branch.shape)).toEqual(expect.arrayContaining(['writable', 'disableable']));
}
});
it('keeps `disableable: true` beside `writable: false` — neither verdict is derived from the other', () => {
const parsed = InstalledPackageAtEitherStageSchema.parse({ ...GLOB_ROW, writable: false, disableable: true });
expect(parsed).toMatchObject({ writable: false, disableable: true });
});
it('is not part of the registry RECORD: the record schemas strip it', () => {
expect(InstalledPackageSchema.parse(GLOB_ROW)).not.toHaveProperty('disableable');
expect(AssembledInstalledPackageSchema.parse(ASSEMBLED_ROW)).not.toHaveProperty('disableable');
});
});
describe('`InstalledPackageAtEitherStageSchema` admits both stages and NOTHING else', () => {
it('parses the authoring row', () => {
expect(InstalledPackageAtEitherStageSchema.safeParse(GLOB_ROW).success).toBe(true);
});
it('parses the assembled row', () => {
expect(InstalledPackageAtEitherStageSchema.safeParse(ASSEMBLED_ROW).success).toBe(true);
});
it('⛔ REFUSES a row belonging to neither stage — this is not road C', () => {
// Road C would have widened `objects` to `(string | ObjectDef)[]`, which
// accepts exactly this. A union over two whole CLOSED stages does not: the
// mixed array parses through neither branch.
const verdict = InstalledPackageAtEitherStageSchema.safeParse(MIXED_ROW);
expect(verdict.success).toBe(false);
});
it('⛔ still refuses an unknown key INSIDE the manifest, on both branches', () => {
// `ManifestSchema` is `strictObject` and the assembled body inherits that
// close, so the union cannot become a hole either stage does not have.
for (const row of [GLOB_ROW, ASSEMBLED_ROW]) {
const typo = { ...row, manifest: { ...row.manifest, namesapce: 'stage' } };
expect(InstalledPackageAtEitherStageSchema.safeParse(typo).success).toBe(false);
}
});
});
describe('the set the record stage must RE-DECLARE is MEASURED, never hand-picked', () => {
/** Does this schema have a JSON Schema form at all? */
const emits = (schema: unknown): boolean => {
try {
z.toJSONSchema(schema as never, { io: 'input' } as never);
return true;
} catch {
return false;
}
};
it('exactly `functions` and `hooks` have no JSON form on the assembled body', () => {
// The two published response schemas below embed the row, whose manifest is
// the RECORD stage. Any collection with no JSON form makes them BOTH vanish
// from `json-schema/api/`, which the build's disappearance ratchet refuses
// — so the record stage declares exactly this set in its lowered form, and
// this pin is what keeps the two in step. A new non-serialisable collection
// reddens HERE, naming itself, rather than unpublishing two responses.
const shape = (AssembledPackageBodySchema as unknown as { shape: Record<string, unknown> }).shape;
const noJsonForm = Object.keys(shape).filter((k) => !emits(shape[k]));
expect(noJsonForm.sort()).toEqual(['functions', 'hooks']);
});
it('lit control: the body itself does not emit, the narrowed row does', () => {
// Without both halves this pin could pass while measuring nothing.
expect(emits(AssembledPackageBodySchema)).toBe(false);
expect(emits(ListInstalledPackagesResponseSchema)).toBe(true);
expect(emits(GetInstalledPackageResponseSchema)).toBe(true);
});
});
describe('the row\'s manifest is the RECORD stage — a declaration, ⛔ not `z.unknown()`', () => {
/**
* What `toRecordManifest` really leaves on a `GET /packages` row: each
* `functions` declaration MINUS its callable, and a hook whose inline handler
* is gone. Until #17518 both keys were `z.unknown().optional()` here, i.e.
* accepted without being checked.
*/
const RECORD_ROW = {
...LIFECYCLE,
manifest: {
...MANIFEST_BASE,
objects: [{ name: 'stage_lead', fields: { title: { type: 'text' } } }],
functions: {
summarizeCompletedTask: { effect: 'pure' },
sweepProjectHealth: { effect: 'writes' },
},
hooks: [{ name: 'on_insert', object: 'stage_lead', events: ['beforeInsert'] }],
},
};
it('parses a row carrying the residual the projection really produces', () => {
expect(AssembledInstalledPackageSchema.safeParse(RECORD_ROW).success).toBe(true);
expect(InstalledPackageAtEitherStageSchema.safeParse(RECORD_ROW).success).toBe(true);
});
it('parses a row carrying what `objectstack build` lowered', () => {
const lowered = {
...RECORD_ROW,
manifest: {
...RECORD_ROW.manifest,
functions: { bare: 'bare', declared: { handler: 'declared', effect: 'writes' } },
hooks: [{ name: 'on_insert', object: 'stage_lead', events: ['beforeInsert'], handler: 'on_insert' }],
},
};
expect(AssembledInstalledPackageSchema.safeParse(lowered).success).toBe(true);
});
it('⛔ REFUSES a live callable — a row the registry can never serve', () => {
// The direction that matters: the two keys moved from "accepts anything" to
// a declaration, so a value no JSON row can hold is refused by name instead
// of waved through. ⛔ Never widen either key back to `unknown` to make a
// payload fit: a row parsing through neither declared stage is a producer
// defect.
const live = {
...RECORD_ROW,
manifest: { ...RECORD_ROW.manifest, functions: { sweepProjectHealth: () => 'ran' } },
};
const verdict = AssembledInstalledPackageSchema.safeParse(live);
expect(verdict.success).toBe(false);
expect(verdict.error!.issues.some((i) => i.path.join('.').startsWith('manifest.functions'))).toBe(true);
});
it('⛔ still refuses the AUTHORING spelling of `objects` — the stage boundary did not move', () => {
expect(AssembledInstalledPackageSchema.safeParse(GLOB_ROW).success).toBe(false);
});
});
describe('the read-API responses are declared at both stages', () => {
const envelope = (data: unknown) => ({ success: true, data });
it('`ListInstalledPackagesResponseSchema` parses a list of either stage', () => {
for (const row of [GLOB_ROW, ASSEMBLED_ROW]) {
const verdict = ListInstalledPackagesResponseSchema.safeParse(
envelope({ packages: [row], total: 1, hasMore: false }),
);
expect(verdict.success).toBe(true);
}
});
it('`GetInstalledPackageResponseSchema` parses either stage', () => {
for (const row of [GLOB_ROW, ASSEMBLED_ROW]) {
expect(GetInstalledPackageResponseSchema.safeParse(envelope(row)).success).toBe(true);
}
});
it('both responses still refuse a row that is at NEITHER stage', () => {
expect(ListInstalledPackagesResponseSchema.safeParse(
envelope({ packages: [MIXED_ROW], total: 1, hasMore: false }),
).success).toBe(false);
expect(GetInstalledPackageResponseSchema.safeParse(envelope(MIXED_ROW)).success).toBe(false);
});
});
// ==========================================
// #18058 — the install contract names the door that serves, and the shapes it
// is actually reached with
// ==========================================
/**
* The card: `PackageInstallRequestSchema` was declared, published and bound to
* `POST /api/v1/packages/install`, a path nothing mounts, while the door that
* serves — `POST /api/v1/packages` — had no declared request contract at all.
* Ruling A (batch #148 item 4) rebinds the contract to the live door and
* reconciles it to what that door measurably accepts.
*
* Every case below is a body a first-party caller really sends, or the
* published example a reader really copies. ⛔ None is constructed to fit the
* schema; each names where it was taken from — and where a real caller's body
* is REFUSED, that is what is pinned, under a name that says so. A fixture
* edited until it parses is the failure mode this block exists to prevent:
* it reports agreement between a declaration and traffic that never met.
*/
describe('install contract bound to the live door', () => {
/** The client SDK's pinned manifest — `packages/client/src/client.test.ts`. */
const SDK_MANIFEST = { id: 'com.acme.crm', name: 'Acme CRM', version: '1.0.0', type: 'app' };
/**
* The published README example — `packages/client/README.md`, the acceptance
* fixture the ruling names. It is transcribed through the SDK's own wrapping
* (`index.ts`: `{ manifest, settings, enableOnInstall, ...overwrite }`), so
* this asserts the body that leaves the process, not a hand-built one.
*/
const README_MANIFEST = {
id: 'com.vendor.plugin',
name: 'Vendor Plugin',
namespace: 'vendor',
version: '1.0.0',
type: 'app',
};
it('the contract-map entry names the serving door, with the phantom path gone', () => {
expect(PackageApiContracts.installPackage.method).toBe('POST');
expect(PackageApiContracts.installPackage.path).toBe('/api/v1/packages');
// The whole map, so the phantom cannot come back under another key.
const paths = Object.values(PackageApiContracts).map((c) => c.path);
expect(paths.filter((p) => p.includes('/install'))).toEqual([]);
});
it('the bound input is the BODY schema, so both declared forms reach it', () => {
expect(PackageApiContracts.installPackage.input).toBe(PackageInstallBodySchema);
});
describe('`overwrite` is declared, so a parse carries it instead of stripping it', () => {
it('survives the parse with its value intact', () => {
const verdict = PackageInstallRequestSchema.safeParse({
manifest: SDK_MANIFEST,
overwrite: true,
});
expect(verdict.success).toBe(true);
// ⭐ The line this half of the card exists for: before it was declared,
// this key parsed green and came out GONE — a deliberate re-install
// silently demoted to a 409.
expect(verdict.data?.overwrite).toBe(true);
});
it('stays optional — the SDK omits it unless asked, and the 409 guard depends on that', () => {
const verdict = PackageInstallRequestSchema.safeParse({ manifest: SDK_MANIFEST });
expect(verdict.success).toBe(true);
expect(verdict.data && 'overwrite' in verdict.data).toBe(false);
});
it('is still a boolean — a string `overwrite` is refused, not coerced', () => {
const verdict = PackageInstallRequestSchema.safeParse({
manifest: SDK_MANIFEST,
overwrite: 'true',
});
expect(verdict.success).toBe(false);
});
});
describe('the two declared body forms — disjoint, and BOTH closed', () => {
it('parses the WRAPPED form the client SDK sends', () => {
const body = { manifest: SDK_MANIFEST, settings: undefined, enableOnInstall: true };
expect(PackageInstallBodySchema.safeParse(body).success).toBe(true);
});
it('parses a COMPLETE manifest posted BARE — the form the door reads as `body.manifest || body`', () => {
// The bare form's green fixture is a manifest that is complete. The
// callers that post bare bodies post complete ones too, since PR #20218
// gave them the `type` they lacked: the block below transcribes them,
// beside the incomplete bodies they used to post.
const bare = { id: 'com.acme.crm', name: 'com.acme.crm', namespace: 'crm', version: '1.0.0', type: 'app' };
expect(PackageInstallBodySchema.safeParse(bare).success).toBe(true);
});
it('the two branches are DISJOINT — a wrapped body never falls through to the bare one', () => {
// `manifest` is not a manifest key and `ManifestSchema` is strict, so the
// only branch a wrapped body can satisfy is the wrapped one.
expect(ManifestSchema.safeParse({ manifest: SDK_MANIFEST }).success).toBe(false);
});
it('refuses a body that is NEITHER form', () => {
// A wrapper around something that is not a manifest: fails branch 1 on
// the manifest's own keys and branch 2 on `manifest` being unknown.
expect(PackageInstallBodySchema.safeParse({ manifest: { label: 'nope' } }).success).toBe(false);
expect(PackageInstallBodySchema.safeParse({ label: 'nope' }).success).toBe(false);
});
it('the BARE form carries no install options — they are refused, never dropped', () => {
const verdict = PackageInstallBodySchema.safeParse({ ...SDK_MANIFEST, overwrite: true });
expect(verdict.success).toBe(false);
});
/**
* ⭐ The WRAPPED branch is CLOSED — an unknown top-level key is refused by
* name, as the manifest's and the bare form's unknown keys are (decision
* batch #227 item 3, letter A; ruling record `5856869656`).
*
* What this pinned before was the opposite: the wrapped branch was strip
* mode, so `{ manifest, enabledOnInstall: false }` parsed green with the
* misspelled key DROPPED, and the door installed the package ENABLED — the
* caller's explicit `false` inverted. Each refusal is read at BOTH doors of
* this declaration: the union the install route is bound to, and the
* wrapped branch alone, whose issue is the one the install door locates
* and surfaces.
*/
describe('the WRAPPED branch refuses an unknown top-level key by name', () => {
/** The wrapped branch's own verdict: one `unrecognized_keys` issue, at the top level, naming the key. */