@peers-app/peers-sdk 0.27.3 → 0.27.5
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.
- package/dist/contracts/contract-proxy.d.ts +7 -0
- package/dist/contracts/contract-proxy.js +19 -2
- package/dist/contracts/contract-transport.d.ts +2 -1
- package/dist/contracts/contract-transport.js +24 -2
- package/dist/contracts/create-local-consumer.js +16 -1
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/system/index.d.ts +2 -0
- package/dist/contracts/system/index.js +2 -0
- package/dist/contracts/system/invites-contract.js +2 -1
- package/dist/contracts/system/sync-check-contract.d.ts +97 -0
- package/dist/contracts/system/sync-check-contract.js +115 -0
- package/dist/contracts/tool-arguments.d.ts +15 -0
- package/dist/contracts/tool-arguments.js +41 -0
- package/dist/contracts/tool-catalog-service.js +2 -12
- package/dist/contracts/tool-catalog.js +6 -2
- package/dist/data/change-tracking.d.ts +40 -0
- package/dist/data/change-tracking.js +89 -0
- package/dist/data/orm/types.d.ts +24 -7
- package/dist/data/orm/types.js +97 -24
- package/dist/define/manifest.js +6 -34
- package/dist/device/binary-peer-connection-v2.d.ts +7 -15
- package/dist/device/binary-peer-connection-v2.js +14 -30
- package/dist/device/connection.d.ts +34 -43
- package/dist/device/connection.js +188 -186
- package/dist/device/device.d.ts +1 -8
- package/dist/device/device.js +1 -30
- package/dist/device/socket.type.d.ts +6 -12
- package/dist/package-loader/package-loader.js +27 -22
- package/dist/system-ids.d.ts +5 -0
- package/dist/system-ids.js +6 -1
- package/package.json +4 -2
- package/dist/context/user-context-identity.test.d.ts +0 -1
- package/dist/context/user-context-identity.test.js +0 -220
- package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
- package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
- package/dist/contracts/__tests__/also-implements.test.js +0 -110
- package/dist/contracts/__tests__/builder.test.d.ts +0 -1
- package/dist/contracts/__tests__/builder.test.js +0 -669
- package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-events.test.js +0 -199
- package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-observables.test.js +0 -290
- package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
- package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
- package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
- package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
- package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-transport.test.js +0 -163
- package/dist/contracts/__tests__/extract.test.d.ts +0 -1
- package/dist/contracts/__tests__/extract.test.js +0 -145
- package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
- package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
- package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
- package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
- package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
- package/dist/contracts/__tests__/integration.test.d.ts +0 -1
- package/dist/contracts/__tests__/integration.test.js +0 -348
- package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
- package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
- package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
- package/dist/contracts/__tests__/playground.test.d.ts +0 -1
- package/dist/contracts/__tests__/playground.test.js +0 -216
- package/dist/contracts/__tests__/registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/registry.test.js +0 -238
- package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
- package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/system-contracts.test.js +0 -247
- package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
- package/dist/contracts/__tests__/target-dispatch.js +0 -24
- package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
- package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
- package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
- package/dist/contracts/__tests__/validate.test.d.ts +0 -1
- package/dist/contracts/__tests__/validate.test.js +0 -991
- package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
- package/dist/contracts/__tests__/workflow-context.test.js +0 -50
- package/dist/data/access-level.test.d.ts +0 -1
- package/dist/data/access-level.test.js +0 -53
- package/dist/data/change-tracking.test.d.ts +0 -1
- package/dist/data/change-tracking.test.js +0 -62
- package/dist/data/files/files.test.d.ts +0 -1
- package/dist/data/files/files.test.js +0 -770
- package/dist/data/group-members.test.d.ts +0 -1
- package/dist/data/group-members.test.js +0 -336
- package/dist/data/group-share.test.d.ts +0 -1
- package/dist/data/group-share.test.js +0 -110
- package/dist/data/groups.test.d.ts +0 -1
- package/dist/data/groups.test.js +0 -153
- package/dist/data/orm/cursor.test.d.ts +0 -1
- package/dist/data/orm/cursor.test.js +0 -314
- package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
- package/dist/data/orm/data-query.mongo.test.js +0 -367
- package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
- package/dist/data/orm/data-query.sqlite.test.js +0 -365
- package/dist/data/orm/data-query.test.d.ts +0 -1
- package/dist/data/orm/data-query.test.js +0 -545
- package/dist/data/orm/dependency-injection.test.d.ts +0 -1
- package/dist/data/orm/dependency-injection.test.js +0 -171
- package/dist/data/orm/event-registry.test.d.ts +0 -1
- package/dist/data/orm/event-registry.test.js +0 -44
- package/dist/data/orm/multi-cursors.test.d.ts +0 -1
- package/dist/data/orm/multi-cursors.test.js +0 -463
- package/dist/data/orm/sql.data-source.test.d.ts +0 -1
- package/dist/data/orm/sql.data-source.test.js +0 -731
- package/dist/data/orm/table-container-events.test.d.ts +0 -1
- package/dist/data/orm/table-container-events.test.js +0 -101
- package/dist/data/orm/table-container.test.d.ts +0 -1
- package/dist/data/orm/table-container.test.js +0 -273
- package/dist/data/orm/table.event-source.test.d.ts +0 -1
- package/dist/data/orm/table.event-source.test.js +0 -331
- package/dist/data/orm/types.test.d.ts +0 -1
- package/dist/data/orm/types.test.js +0 -409
- package/dist/data/package-table-identity.test.d.ts +0 -1
- package/dist/data/package-table-identity.test.js +0 -46
- package/dist/data/package-version-permissions.test.d.ts +0 -1
- package/dist/data/package-version-permissions.test.js +0 -107
- package/dist/data/package-version-resolver.test.d.ts +0 -4
- package/dist/data/package-version-resolver.test.js +0 -543
- package/dist/data/package-versions.test.d.ts +0 -1
- package/dist/data/package-versions.test.js +0 -227
- package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
- package/dist/data/persistent-vars.conflict.test.js +0 -126
- package/dist/data/persistent-vars.migration.test.d.ts +0 -1
- package/dist/data/persistent-vars.migration.test.js +0 -133
- package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
- package/dist/data/persistent-vars.package-scope.test.js +0 -27
- package/dist/data/sync-recovery-queue.test.d.ts +0 -1
- package/dist/data/sync-recovery-queue.test.js +0 -215
- package/dist/data/table-signing.test.d.ts +0 -1
- package/dist/data/table-signing.test.js +0 -118
- package/dist/data/tool-access.test.d.ts +0 -1
- package/dist/data/tool-access.test.js +0 -166
- package/dist/data/user-permissions.test.d.ts +0 -1
- package/dist/data/user-permissions.test.js +0 -305
- package/dist/data/user-trust-levels.test.d.ts +0 -1
- package/dist/data/user-trust-levels.test.js +0 -37
- package/dist/define/also-implements.test.d.ts +0 -1
- package/dist/define/also-implements.test.js +0 -123
- package/dist/define/declare-contract.test.d.ts +0 -1
- package/dist/define/declare-contract.test.js +0 -573
- package/dist/define/define.test.d.ts +0 -1
- package/dist/define/define.test.js +0 -1010
- package/dist/define/empty-fields.test.d.ts +0 -1
- package/dist/define/empty-fields.test.js +0 -55
- package/dist/define/events-observables.test.d.ts +0 -1
- package/dist/define/events-observables.test.js +0 -1013
- package/dist/define/serve-members.test.d.ts +0 -1
- package/dist/define/serve-members.test.js +0 -630
- package/dist/define/vars.test.d.ts +0 -1
- package/dist/define/vars.test.js +0 -39
- package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
- package/dist/device/binary-peer-connection-v2.test.js +0 -730
- package/dist/device/binary-peer-connection.d.ts +0 -58
- package/dist/device/binary-peer-connection.js +0 -516
- package/dist/device/binary-peer-connection.test.d.ts +0 -1
- package/dist/device/binary-peer-connection.test.js +0 -184
- package/dist/device/connection.test.d.ts +0 -1
- package/dist/device/connection.test.js +0 -613
- package/dist/device/device-election.test.d.ts +0 -1
- package/dist/device/device-election.test.js +0 -516
- package/dist/device/device.test.d.ts +0 -1
- package/dist/device/device.test.js +0 -243
- package/dist/device/frame-cipher.test.d.ts +0 -1
- package/dist/device/frame-cipher.test.js +0 -219
- package/dist/device/get-trust-level-fn.test.d.ts +0 -1
- package/dist/device/get-trust-level-fn.test.js +0 -685
- package/dist/device/streamed-socket.d.ts +0 -23
- package/dist/device/streamed-socket.js +0 -255
- package/dist/device/streamed-socket.test.d.ts +0 -1
- package/dist/device/streamed-socket.test.js +0 -216
- package/dist/device/tx-encoding.test.d.ts +0 -1
- package/dist/device/tx-encoding.test.js +0 -295
- package/dist/device-pairing/cpace.test.d.ts +0 -1
- package/dist/device-pairing/cpace.test.js +0 -116
- package/dist/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/device-pairing/device-pairing.test.js +0 -211
- package/dist/hlc.test.d.ts +0 -1
- package/dist/hlc.test.js +0 -45
- package/dist/host-credentials.test.d.ts +0 -1
- package/dist/host-credentials.test.js +0 -88
- package/dist/identity/account-email.test.d.ts +0 -1
- package/dist/identity/account-email.test.js +0 -59
- package/dist/identity/anchor-document.test.d.ts +0 -1
- package/dist/identity/anchor-document.test.js +0 -16
- package/dist/identity/anchor-resolution.test.d.ts +0 -1
- package/dist/identity/anchor-resolution.test.js +0 -130
- package/dist/identity/key-change.test.d.ts +0 -1
- package/dist/identity/key-change.test.js +0 -811
- package/dist/invites/group-approval.test.d.ts +0 -1
- package/dist/invites/group-approval.test.js +0 -223
- package/dist/invites/invite-token.test.d.ts +0 -1
- package/dist/invites/invite-token.test.js +0 -123
- package/dist/keys.test.d.ts +0 -1
- package/dist/keys.test.js +0 -336
- package/dist/logging/console-logger.test.d.ts +0 -1
- package/dist/logging/console-logger.test.js +0 -300
- package/dist/logging/console-logs.table.test.d.ts +0 -1
- package/dist/logging/console-logs.table.test.js +0 -156
- package/dist/observable.test.d.ts +0 -1
- package/dist/observable.test.js +0 -309
- package/dist/package-build/build-package.test.d.ts +0 -1
- package/dist/package-build/build-package.test.js +0 -204
- package/dist/package-build/contract-add.test.d.ts +0 -1
- package/dist/package-build/contract-add.test.js +0 -467
- package/dist/package-build/freeze-contracts.test.d.ts +0 -1
- package/dist/package-build/freeze-contracts.test.js +0 -355
- package/dist/package-installer/package-author-signing.test.d.ts +0 -1
- package/dist/package-installer/package-author-signing.test.js +0 -200
- package/dist/package-installer/package-cloner.test.d.ts +0 -1
- package/dist/package-installer/package-cloner.test.js +0 -278
- package/dist/package-installer/package-creator.test.d.ts +0 -1
- package/dist/package-installer/package-creator.test.js +0 -908
- package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
- package/dist/package-installer/package-dev-tools.test.js +0 -64
- package/dist/package-installer/package-installer.test.d.ts +0 -1
- package/dist/package-installer/package-installer.test.js +0 -882
- package/dist/package-installer/package-propagation.test.d.ts +0 -1
- package/dist/package-installer/package-propagation.test.js +0 -1269
- package/dist/package-installer/package-publisher.test.d.ts +0 -1
- package/dist/package-installer/package-publisher.test.js +0 -153
- package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
- package/dist/package-installer/package-remote-checker.test.js +0 -334
- package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
- package/dist/package-installer/package-seed-installer.test.js +0 -123
- package/dist/package-installer/package-tarball.test.d.ts +0 -1
- package/dist/package-installer/package-tarball.test.js +0 -75
- package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
- package/dist/package-installer/peers-core-installer.test.js +0 -49
- package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
- package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
- package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
- package/dist/package-loader/contract-package-loader.test.js +0 -274
- package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
- package/dist/package-loader/host-authority-loading.test.js +0 -104
- package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
- package/dist/package-loader/host-dispatch-policy.test.js +0 -56
- package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
- package/dist/package-loader/isolated-artifact.test.js +0 -688
- package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
- package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-table-gateway.test.js +0 -633
- package/dist/package-loader/package-loader.test.d.ts +0 -1
- package/dist/package-loader/package-loader.test.js +0 -1764
- package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
- package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
- package/dist/serial-json.compat.test.d.ts +0 -1
- package/dist/serial-json.compat.test.js +0 -369
- package/dist/serial-json.test.d.ts +0 -1
- package/dist/serial-json.test.js +0 -401
- package/dist/testing/mock-host-contract.test.d.ts +0 -1
- package/dist/testing/mock-host-contract.test.js +0 -782
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -232
|
@@ -1,908 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const system_ids_1 = require("../system-ids");
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const package_creator_1 = require("./package-creator");
|
|
6
|
-
const package_dev_tools_1 = require("./package-dev-tools");
|
|
7
|
-
// --- Mocks for SDK internals ---
|
|
8
|
-
const mockSignAndSavePkg = jest.fn();
|
|
9
|
-
const mockGetPkg = jest.fn();
|
|
10
|
-
jest.mock("../data/packages", () => ({
|
|
11
|
-
Packages: (dataContext) => ({
|
|
12
|
-
signAndSave: (...args) => mockSignAndSavePkg(dataContext, ...args),
|
|
13
|
-
get: (packageId) => mockGetPkg(dataContext, packageId),
|
|
14
|
-
}),
|
|
15
|
-
}));
|
|
16
|
-
const mockGroupDeviceVar = jest.fn();
|
|
17
|
-
const mockPersistentVarsSave = jest.fn();
|
|
18
|
-
const mockPersistentVarsFindOne = jest.fn();
|
|
19
|
-
jest.mock("../data/persistent-vars", () => ({
|
|
20
|
-
groupDeviceVar: (...args) => mockGroupDeviceVar(...args),
|
|
21
|
-
PersistentVars: () => ({
|
|
22
|
-
save: mockPersistentVarsSave,
|
|
23
|
-
findOne: mockPersistentVarsFindOne,
|
|
24
|
-
}),
|
|
25
|
-
}));
|
|
26
|
-
const mockNewKeys = jest.fn();
|
|
27
|
-
jest.mock("../keys", () => {
|
|
28
|
-
const actual = jest.requireActual("../keys");
|
|
29
|
-
return {
|
|
30
|
-
...actual,
|
|
31
|
-
newKeys: (...args) => mockNewKeys(...args),
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
// Mock installPackageFromBundles and getPackageInfo from the same package
|
|
35
|
-
const mockInstallPackageFromBundles = jest.fn();
|
|
36
|
-
const mockGetPackageInfo = jest.fn();
|
|
37
|
-
jest.mock("./package-installer", () => ({
|
|
38
|
-
installPackageFromBundles: (...args) => mockInstallPackageFromBundles(...args),
|
|
39
|
-
getPackageInfo: (...args) => mockGetPackageInfo(...args),
|
|
40
|
-
}));
|
|
41
|
-
const { newKeys: realNewKeys } = jest.requireActual("../keys");
|
|
42
|
-
const generatedKeys = realNewKeys();
|
|
43
|
-
const sourceKeys = realNewKeys();
|
|
44
|
-
const targetKeys = realNewKeys();
|
|
45
|
-
// --- Test utilities ---
|
|
46
|
-
function makeMockDeps(files, shellExec) {
|
|
47
|
-
return {
|
|
48
|
-
fs: {
|
|
49
|
-
readFile: jest.fn(async (path) => {
|
|
50
|
-
if (files[path] !== undefined)
|
|
51
|
-
return files[path];
|
|
52
|
-
throw new Error(`ENOENT: ${path}`);
|
|
53
|
-
}),
|
|
54
|
-
writeFile: jest.fn(async () => { }),
|
|
55
|
-
exists: jest.fn(async (path) => {
|
|
56
|
-
if (path in files)
|
|
57
|
-
return true;
|
|
58
|
-
const dirPrefix = path.endsWith("/") ? path : `${path}/`;
|
|
59
|
-
return Object.keys(files).some((f) => f.startsWith(dirPrefix));
|
|
60
|
-
}),
|
|
61
|
-
readJson: jest.fn(async (path) => {
|
|
62
|
-
if (files[path] === undefined)
|
|
63
|
-
throw new Error(`ENOENT: ${path}`);
|
|
64
|
-
return JSON.parse(files[path]);
|
|
65
|
-
}),
|
|
66
|
-
},
|
|
67
|
-
shell: {
|
|
68
|
-
exec: shellExec ?? jest.fn(async () => ({ stdout: "", stderr: "" })),
|
|
69
|
-
},
|
|
70
|
-
resolvePath: (...segments) => segments.join("/"),
|
|
71
|
-
packagesRootDir: "/packages",
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function mockDataContext() {
|
|
75
|
-
return {
|
|
76
|
-
dataContextId: (0, utils_1.newid)(),
|
|
77
|
-
packageLoader: {
|
|
78
|
-
loadPackage: jest.fn().mockResolvedValue(undefined),
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
// --- Tests ---
|
|
83
|
-
beforeEach(() => {
|
|
84
|
-
jest.clearAllMocks();
|
|
85
|
-
mockGetPkg.mockReset().mockResolvedValue(undefined);
|
|
86
|
-
mockPersistentVarsFindOne.mockReset().mockResolvedValue(undefined);
|
|
87
|
-
mockNewKeys.mockReturnValue(generatedKeys);
|
|
88
|
-
mockPersistentVarsSave.mockReset();
|
|
89
|
-
});
|
|
90
|
-
describe("nameToFolderSlug", () => {
|
|
91
|
-
it("converts a simple name", () => {
|
|
92
|
-
expect((0, package_creator_1.nameToFolderSlug)("My Widget")).toBe("my-widget");
|
|
93
|
-
});
|
|
94
|
-
it("converts camelCase names", () => {
|
|
95
|
-
expect((0, package_creator_1.nameToFolderSlug)("camelCaseThing")).toBe("camel-case-thing");
|
|
96
|
-
});
|
|
97
|
-
it("strips special characters", () => {
|
|
98
|
-
expect((0, package_creator_1.nameToFolderSlug)("Hello! World?")).toBe("hello-world");
|
|
99
|
-
});
|
|
100
|
-
it("collapses multiple spaces", () => {
|
|
101
|
-
expect((0, package_creator_1.nameToFolderSlug)("too many spaces")).toBe("too-many-spaces");
|
|
102
|
-
});
|
|
103
|
-
it("preserves non-ASCII names and allocates a folder for symbol-only names", () => {
|
|
104
|
-
expect((0, package_creator_1.nameToFolderSlug)("買い物")).toBe("買い物");
|
|
105
|
-
expect((0, package_creator_1.nameToFolderSlug)("Café 漢字")).toBe("caf"); // Keep older creators' folder names.
|
|
106
|
-
const first = (0, package_creator_1.nameToFolderSlug)("🛒");
|
|
107
|
-
expect(first).toMatch(/^package-[a-z0-9]{25}$/);
|
|
108
|
-
expect((0, package_creator_1.nameToFolderSlug)("🛒")).not.toBe(first);
|
|
109
|
-
});
|
|
110
|
-
it("keeps long ASCII and Unicode names within a filesystem component's byte limit", () => {
|
|
111
|
-
for (const name of ["Long Name ".repeat(40), "漢".repeat(100)]) {
|
|
112
|
-
const folder = (0, package_creator_1.nameToFolderSlug)(name);
|
|
113
|
-
expect(Buffer.byteLength(folder, "utf8")).toBeLessThanOrEqual(255);
|
|
114
|
-
expect((0, package_creator_1.nameToFolderSlug)(name)).toBe(folder);
|
|
115
|
-
expect((0, package_creator_1.nameToFolderSlug)(`${name}more`)).not.toBe(folder);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
describe("createPackage", () => {
|
|
120
|
-
it("fails before scaffolding when Node.js or npm is missing", async () => {
|
|
121
|
-
const shellExec = jest.fn(async (cmd) => {
|
|
122
|
-
if (cmd === "npm --version") {
|
|
123
|
-
throw new Error("/bin/sh: npm: command not found");
|
|
124
|
-
}
|
|
125
|
-
return { stdout: "", stderr: "" };
|
|
126
|
-
});
|
|
127
|
-
const deps = makeMockDeps({}, shellExec);
|
|
128
|
-
deps.fs.exists.mockResolvedValue(false);
|
|
129
|
-
await expect((0, package_creator_1.createPackage)(mockDataContext(), deps, { name: "KidsTube" })).rejects.toThrow(package_dev_tools_1.MISSING_NODE_MESSAGE);
|
|
130
|
-
expect(deps.fs.writeFile).not.toHaveBeenCalled();
|
|
131
|
-
expect(shellExec.mock.calls.map((call) => call[0])).toEqual([
|
|
132
|
-
"git --version",
|
|
133
|
-
"node --version",
|
|
134
|
-
"npm --version",
|
|
135
|
-
]);
|
|
136
|
-
});
|
|
137
|
-
it("creates a package using local template cache with correct steps", async () => {
|
|
138
|
-
const templatePkgJson = JSON.stringify({
|
|
139
|
-
name: "peers-package-template",
|
|
140
|
-
version: "1.0.0",
|
|
141
|
-
peers: {},
|
|
142
|
-
repository: { url: "https://github.com/peers-app/peers-package-template" },
|
|
143
|
-
});
|
|
144
|
-
const idsContent = JSON.stringify({
|
|
145
|
-
packageId: "<package-id>",
|
|
146
|
-
packageName: "<package-name>",
|
|
147
|
-
screenId: "<app-screen-id>",
|
|
148
|
-
contractId: "<contract-id>",
|
|
149
|
-
stateObservableName: "state",
|
|
150
|
-
});
|
|
151
|
-
const deps = makeMockDeps({});
|
|
152
|
-
const dc = mockDataContext();
|
|
153
|
-
// Simulate: location and cache do not exist; ids.json exists after the template copy.
|
|
154
|
-
deps.fs.exists.mockImplementation(async (path) => {
|
|
155
|
-
if (path === "/packages/my-widget")
|
|
156
|
-
return false;
|
|
157
|
-
if (path === "/packages/.peers-package-template")
|
|
158
|
-
return false;
|
|
159
|
-
if (path.includes("ids.json"))
|
|
160
|
-
return true;
|
|
161
|
-
return false;
|
|
162
|
-
});
|
|
163
|
-
deps.fs.readJson.mockResolvedValue(JSON.parse(templatePkgJson));
|
|
164
|
-
deps.fs.readFile.mockResolvedValue(idsContent);
|
|
165
|
-
const pvarSetter = jest.fn();
|
|
166
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
167
|
-
const mockPv = { packageVersionId: "pv001", packageId: "pkg001" };
|
|
168
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
169
|
-
packageVersion: mockPv,
|
|
170
|
-
loaded: undefined,
|
|
171
|
-
unchanged: false,
|
|
172
|
-
});
|
|
173
|
-
const result = await (0, package_creator_1.createPackage)(dc, deps, {
|
|
174
|
-
name: "My Widget",
|
|
175
|
-
author: "Test User",
|
|
176
|
-
});
|
|
177
|
-
const execCalls = deps.shell.exec.mock.calls.map((c) => c[0]);
|
|
178
|
-
expect(execCalls.slice(0, 3)).toEqual(["git --version", "node --version", "npm --version"]);
|
|
179
|
-
// Verify template was cloned to cache (not directly to location)
|
|
180
|
-
expect(execCalls).toContain("git clone https://github.com/peers-app/peers-package-template.git /packages/.peers-package-template");
|
|
181
|
-
// Verify cp -r from cache to location
|
|
182
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("cp -r /packages/.peers-package-template/. /packages/my-widget");
|
|
183
|
-
// Should NOT have cloned directly to location
|
|
184
|
-
expect(execCalls).not.toContain(expect.stringContaining("git clone") && expect.stringContaining("/packages/my-widget"));
|
|
185
|
-
// Verify package.json was patched
|
|
186
|
-
expect(deps.fs.writeFile).toHaveBeenCalledWith("/packages/my-widget/package.json", expect.any(String));
|
|
187
|
-
const writtenPkgJson = JSON.parse(deps.fs.writeFile.mock.calls.find((c) => c[0].includes("package.json"))[1]);
|
|
188
|
-
expect(writtenPkgJson.name).toBe("my-widget");
|
|
189
|
-
expect(writtenPkgJson.author).toBe("Test User");
|
|
190
|
-
expect(writtenPkgJson.peers.packageId).toMatch(/^[a-z0-9]{25}$/);
|
|
191
|
-
expect(writtenPkgJson.repository).toBeUndefined();
|
|
192
|
-
// Verify the isolated package ID source was patched.
|
|
193
|
-
const idsWriteCall = deps.fs.writeFile.mock.calls.find((c) => c[0].includes("ids.json"));
|
|
194
|
-
expect(idsWriteCall).toBeTruthy();
|
|
195
|
-
const writtenIds = JSON.parse(idsWriteCall[1]);
|
|
196
|
-
expect(writtenIds.packageId).toMatch(/^[a-z0-9]{25}$/);
|
|
197
|
-
expect(writtenIds.contractId).toMatch(/^[a-z0-9]{25}$/);
|
|
198
|
-
expect(writtenIds.screenId).toMatch(/^[a-z0-9]{25}$/);
|
|
199
|
-
expect(writtenIds.packageName).toBe("My Widget");
|
|
200
|
-
// Verify initialization commands
|
|
201
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("rm -rf .git", { cwd: "/packages/my-widget" });
|
|
202
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("npm install", { cwd: "/packages/my-widget" });
|
|
203
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("npm run build", { cwd: "/packages/my-widget" });
|
|
204
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("git init", { cwd: "/packages/my-widget" });
|
|
205
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("git add .", { cwd: "/packages/my-widget" });
|
|
206
|
-
expect(deps.shell.exec).toHaveBeenCalledWith('git commit -m "Initial commit"', {
|
|
207
|
-
cwd: "/packages/my-widget",
|
|
208
|
-
});
|
|
209
|
-
// Verify package record was created
|
|
210
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(dc, expect.objectContaining({
|
|
211
|
-
name: "My Widget",
|
|
212
|
-
disabled: false,
|
|
213
|
-
}), { restoreIfDeleted: true, saveAsSnapshot: true });
|
|
214
|
-
// Verify device var was set
|
|
215
|
-
expect(mockGroupDeviceVar).toHaveBeenCalledWith(expect.stringContaining("packageLocalPath_"), expect.any(Object));
|
|
216
|
-
expect(pvarSetter).toHaveBeenCalledWith("/packages/my-widget");
|
|
217
|
-
// Verify installPackageFromBundles was called
|
|
218
|
-
expect(mockInstallPackageFromBundles).toHaveBeenCalledWith(dc, deps, expect.any(String), {
|
|
219
|
-
localPath: "/packages/my-widget",
|
|
220
|
-
});
|
|
221
|
-
expect(result.localPath).toBe("/packages/my-widget");
|
|
222
|
-
expect(result.packageVersion).toBe(mockPv);
|
|
223
|
-
expect(result.templateWarning).toBeUndefined();
|
|
224
|
-
});
|
|
225
|
-
it("returns a stale-template warning when the cached template cannot be refreshed", async () => {
|
|
226
|
-
const shellExec = jest.fn(async (cmd) => {
|
|
227
|
-
if (cmd === "git pull") {
|
|
228
|
-
throw new Error("error: Your local changes to the following files would be overwritten by merge:\n\t.gitignore");
|
|
229
|
-
}
|
|
230
|
-
return { stdout: "", stderr: "" };
|
|
231
|
-
});
|
|
232
|
-
const deps = makeMockDeps({}, shellExec);
|
|
233
|
-
const dc = mockDataContext();
|
|
234
|
-
deps.fs.exists.mockImplementation(async (path) => {
|
|
235
|
-
if (path === "/packages/desk")
|
|
236
|
-
return false;
|
|
237
|
-
if (path === "/packages/.peers-package-template")
|
|
238
|
-
return true;
|
|
239
|
-
return false;
|
|
240
|
-
});
|
|
241
|
-
deps.fs.readJson.mockResolvedValue({ name: "template", peers: {} });
|
|
242
|
-
const pvarSetter = jest.fn();
|
|
243
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
244
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
245
|
-
packageVersion: { packageVersionId: "pv" },
|
|
246
|
-
loaded: undefined,
|
|
247
|
-
unchanged: false,
|
|
248
|
-
});
|
|
249
|
-
const result = await (0, package_creator_1.createPackage)(dc, deps, { name: "Desk" });
|
|
250
|
-
expect(result.templateWarning).toMatch(/stale version/i);
|
|
251
|
-
expect(result.templateWarning).toMatch(/local changes/i);
|
|
252
|
-
expect(result.localPath).toBe("/packages/desk");
|
|
253
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("cp -r /packages/.peers-package-template/. /packages/desk");
|
|
254
|
-
});
|
|
255
|
-
it("registers metadata, path, and signing key when importing an existing package directory", async () => {
|
|
256
|
-
const deps = makeMockDeps({});
|
|
257
|
-
const dc = mockDataContext();
|
|
258
|
-
const personalCtx = mockDataContext();
|
|
259
|
-
deps.fs.exists.mockResolvedValue(true);
|
|
260
|
-
mockGetPackageInfo.mockResolvedValue({
|
|
261
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
262
|
-
name: "existing-pkg",
|
|
263
|
-
description: "Imported package",
|
|
264
|
-
});
|
|
265
|
-
const pvarSetter = jest.fn();
|
|
266
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
267
|
-
const mockPv = { packageVersionId: "pv002", packageId: "00mnkoyo7mizav6tseubjzr3a" };
|
|
268
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
269
|
-
packageVersion: mockPv,
|
|
270
|
-
loaded: undefined,
|
|
271
|
-
unchanged: false,
|
|
272
|
-
});
|
|
273
|
-
const result = await (0, package_creator_1.createPackage)(dc, deps, {
|
|
274
|
-
name: "Existing Pkg",
|
|
275
|
-
location: "/custom/path",
|
|
276
|
-
personalContext: personalCtx,
|
|
277
|
-
});
|
|
278
|
-
expect(deps.shell.exec).not.toHaveBeenCalled();
|
|
279
|
-
expect(mockGetPkg).toHaveBeenCalledWith(dc, "00mnkoyo7mizav6tseubjzr3a");
|
|
280
|
-
expect(mockNewKeys).toHaveBeenCalled();
|
|
281
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledWith(expect.objectContaining({
|
|
282
|
-
name: "packageSigningKey_00mnkoyo7mizav6tseubjzr3a",
|
|
283
|
-
isSecret: true,
|
|
284
|
-
value: { value: generatedKeys.secretKey },
|
|
285
|
-
}), { restoreIfDeleted: true });
|
|
286
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(dc, expect.objectContaining({
|
|
287
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
288
|
-
name: "Existing Pkg",
|
|
289
|
-
description: "Imported package",
|
|
290
|
-
publishPublicKey: generatedKeys.publicKey,
|
|
291
|
-
}), { restoreIfDeleted: true, saveAsSnapshot: true });
|
|
292
|
-
expect(mockGroupDeviceVar).toHaveBeenCalledWith("packageLocalPath_00mnkoyo7mizav6tseubjzr3a", expect.any(Object));
|
|
293
|
-
expect(pvarSetter).toHaveBeenCalledWith("/custom/path");
|
|
294
|
-
expect(mockInstallPackageFromBundles).toHaveBeenCalledWith(dc, deps, "00mnkoyo7mizav6tseubjzr3a", { localPath: "/custom/path" });
|
|
295
|
-
expect(result.packageId).toBe("00mnkoyo7mizav6tseubjzr3a");
|
|
296
|
-
expect(result.localPath).toBe("/custom/path");
|
|
297
|
-
});
|
|
298
|
-
it("reuses an existing publishPublicKey and does not rotate the signing key on re-import", async () => {
|
|
299
|
-
const deps = makeMockDeps({});
|
|
300
|
-
const dc = mockDataContext();
|
|
301
|
-
const personalCtx = mockDataContext();
|
|
302
|
-
deps.fs.exists.mockResolvedValue(true);
|
|
303
|
-
mockGetPackageInfo.mockResolvedValue({
|
|
304
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
305
|
-
name: "existing-pkg",
|
|
306
|
-
});
|
|
307
|
-
mockGetPkg.mockResolvedValue({
|
|
308
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
309
|
-
name: "existing-pkg",
|
|
310
|
-
description: "Old description",
|
|
311
|
-
createdBy: "00m87fbwu96jzf8qnwllly0fd",
|
|
312
|
-
publishPublicKey: "already-established-public-key",
|
|
313
|
-
signature: "sig",
|
|
314
|
-
disabled: false,
|
|
315
|
-
});
|
|
316
|
-
const pvarSetter = jest.fn();
|
|
317
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
318
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
319
|
-
packageVersion: { packageVersionId: "pv002", packageId: "00mnkoyo7mizav6tseubjzr3a" },
|
|
320
|
-
loaded: undefined,
|
|
321
|
-
unchanged: false,
|
|
322
|
-
});
|
|
323
|
-
await (0, package_creator_1.createPackage)(dc, deps, {
|
|
324
|
-
name: "existing-pkg",
|
|
325
|
-
location: "/custom/path",
|
|
326
|
-
personalContext: personalCtx,
|
|
327
|
-
});
|
|
328
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
329
|
-
expect(mockPersistentVarsSave).not.toHaveBeenCalled();
|
|
330
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(dc, expect.objectContaining({
|
|
331
|
-
publishPublicKey: "already-established-public-key",
|
|
332
|
-
createdBy: "00m87fbwu96jzf8qnwllly0fd",
|
|
333
|
-
}), expect.any(Object));
|
|
334
|
-
});
|
|
335
|
-
describe("importing by name across contexts", () => {
|
|
336
|
-
const packageId = "00mnkoyo7mizav6tseubjzr3a";
|
|
337
|
-
let contexts;
|
|
338
|
-
let deps;
|
|
339
|
-
beforeEach(() => {
|
|
340
|
-
contexts = {
|
|
341
|
-
personal: mockDataContext(),
|
|
342
|
-
blankGroup: mockDataContext(),
|
|
343
|
-
group: mockDataContext(),
|
|
344
|
-
otherGroup: mockDataContext(),
|
|
345
|
-
};
|
|
346
|
-
const userContext = {
|
|
347
|
-
userId: contexts.personal.dataContextId,
|
|
348
|
-
userDataContext: contexts.personal,
|
|
349
|
-
groupDataContexts: new Map(Object.values(contexts)
|
|
350
|
-
.slice(1)
|
|
351
|
-
.map((dc) => [dc.dataContextId, dc])),
|
|
352
|
-
};
|
|
353
|
-
for (const dc of Object.values(contexts))
|
|
354
|
-
dc.userContext = userContext;
|
|
355
|
-
deps = makeMockDeps({ "/packages/existing-pkg/package.json": "{}" });
|
|
356
|
-
mockGetPackageInfo.mockResolvedValue({ packageId, description: "Imported package" });
|
|
357
|
-
mockGroupDeviceVar.mockReturnValue(jest.fn());
|
|
358
|
-
mockInstallPackageFromBundles.mockResolvedValue({ packageVersion: { packageId } });
|
|
359
|
-
mockPersistentVarsFindOne.mockResolvedValue({ value: { value: "unreadable-secret" } });
|
|
360
|
-
});
|
|
361
|
-
it.each([
|
|
362
|
-
["group", "personal", ["personal", "blankGroup", "group"]],
|
|
363
|
-
["group", "otherGroup", ["otherGroup", "personal", "blankGroup", "group"]],
|
|
364
|
-
["personal", "group", ["group", "personal"]],
|
|
365
|
-
])("reuses the key from %s when importing into %s", async (source, target, lookups) => {
|
|
366
|
-
mockGetPkg.mockImplementation(async (dc, id) => {
|
|
367
|
-
if (id !== packageId || dc === contexts[target])
|
|
368
|
-
return undefined;
|
|
369
|
-
if (dc === contexts[source]) {
|
|
370
|
-
return {
|
|
371
|
-
publishPublicKey: sourceKeys.publicKey,
|
|
372
|
-
name: "Source name",
|
|
373
|
-
description: "Source description",
|
|
374
|
-
createdBy: (0, utils_1.newid)(),
|
|
375
|
-
disabled: true,
|
|
376
|
-
activePackageVersionId: (0, utils_1.newid)(),
|
|
377
|
-
versionFollowRange: "^1.0.0",
|
|
378
|
-
followVersionTags: ["stable"],
|
|
379
|
-
updateUrl: "source-url",
|
|
380
|
-
remoteRepo: "source-repo",
|
|
381
|
-
signature: "source-signature",
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
if (dc === contexts.personal || dc === contexts.blankGroup) {
|
|
385
|
-
return { publishPublicKey: " \t " };
|
|
386
|
-
}
|
|
387
|
-
return undefined;
|
|
388
|
-
});
|
|
389
|
-
const result = await (0, package_creator_1.createPackage)(contexts[target], deps, {
|
|
390
|
-
name: "Existing Pkg",
|
|
391
|
-
personalContext: contexts.personal,
|
|
392
|
-
});
|
|
393
|
-
expect(mockGetPkg.mock.calls).toEqual(lookups.map((name) => [contexts[name], packageId]));
|
|
394
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(contexts[target], expect.objectContaining({
|
|
395
|
-
packageId,
|
|
396
|
-
name: "Existing Pkg",
|
|
397
|
-
description: "Imported package",
|
|
398
|
-
publishPublicKey: sourceKeys.publicKey,
|
|
399
|
-
createdBy: system_ids_1.peersRootUserId,
|
|
400
|
-
disabled: false,
|
|
401
|
-
activePackageVersionId: undefined,
|
|
402
|
-
versionFollowRange: undefined,
|
|
403
|
-
followVersionTags: undefined,
|
|
404
|
-
updateUrl: undefined,
|
|
405
|
-
remoteRepo: undefined,
|
|
406
|
-
signature: "",
|
|
407
|
-
}), { restoreIfDeleted: true, saveAsSnapshot: true });
|
|
408
|
-
expect(mockInstallPackageFromBundles).toHaveBeenCalledWith(contexts[target], deps, packageId, {
|
|
409
|
-
localPath: "/packages/existing-pkg",
|
|
410
|
-
});
|
|
411
|
-
expect(result.packageVersion).toEqual({ packageId });
|
|
412
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
413
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledWith(expect.objectContaining({
|
|
414
|
-
value: { value: "unreadable-secret" },
|
|
415
|
-
description: expect.stringContaining(`v1:${packageId}:${sourceKeys.publicKey}`),
|
|
416
|
-
}));
|
|
417
|
-
});
|
|
418
|
-
it("keeps the target key without looking up a differing source key", async () => {
|
|
419
|
-
mockGetPkg.mockImplementation(async (dc) => ({
|
|
420
|
-
publishPublicKey: dc === contexts.otherGroup ? targetKeys.publicKey : sourceKeys.publicKey,
|
|
421
|
-
}));
|
|
422
|
-
await (0, package_creator_1.createPackage)(contexts.otherGroup, deps, {
|
|
423
|
-
name: "Existing Pkg",
|
|
424
|
-
personalContext: contexts.personal,
|
|
425
|
-
});
|
|
426
|
-
expect(mockGetPkg.mock.calls).toEqual([[contexts.otherGroup, packageId]]);
|
|
427
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(contexts.otherGroup, expect.objectContaining({ publishPublicKey: targetKeys.publicKey }), expect.any(Object));
|
|
428
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
429
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledWith(expect.objectContaining({
|
|
430
|
-
value: { value: "unreadable-secret" },
|
|
431
|
-
description: expect.stringContaining(`v1:${packageId}:${targetKeys.publicKey}`),
|
|
432
|
-
}));
|
|
433
|
-
});
|
|
434
|
-
it.each([
|
|
435
|
-
"missing",
|
|
436
|
-
"mismatch",
|
|
437
|
-
"lookup-error",
|
|
438
|
-
"empty-target",
|
|
439
|
-
])("fails without installing or changing keys for %s", async (failure) => {
|
|
440
|
-
mockGetPkg.mockImplementation(async (dc) => {
|
|
441
|
-
if (dc === contexts.otherGroup) {
|
|
442
|
-
return failure === "empty-target" ? { publishPublicKey: "" } : undefined;
|
|
443
|
-
}
|
|
444
|
-
if (failure === "lookup-error")
|
|
445
|
-
throw new Error("source lookup failed");
|
|
446
|
-
return failure === "missing" ? undefined : { publishPublicKey: sourceKeys.publicKey };
|
|
447
|
-
});
|
|
448
|
-
if (failure === "mismatch") {
|
|
449
|
-
const { newKeys: realNewKeys } = jest.requireActual("../keys");
|
|
450
|
-
mockPersistentVarsFindOne.mockResolvedValue({ value: { value: realNewKeys().secretKey } });
|
|
451
|
-
}
|
|
452
|
-
await expect((0, package_creator_1.createPackage)(contexts.otherGroup, deps, {
|
|
453
|
-
name: "Existing Pkg",
|
|
454
|
-
personalContext: contexts.personal,
|
|
455
|
-
})).rejects.toThrow(failure === "mismatch"
|
|
456
|
-
? "signing key mismatch"
|
|
457
|
-
: failure === "lookup-error"
|
|
458
|
-
? "source lookup failed"
|
|
459
|
-
: "secret could not be hydrated");
|
|
460
|
-
if (failure === "empty-target") {
|
|
461
|
-
expect(mockGetPkg.mock.calls).toEqual([[contexts.otherGroup, packageId]]);
|
|
462
|
-
}
|
|
463
|
-
expect(mockSignAndSavePkg).not.toHaveBeenCalled();
|
|
464
|
-
expect(mockInstallPackageFromBundles).not.toHaveBeenCalled();
|
|
465
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
466
|
-
expect(mockPersistentVarsSave).not.toHaveBeenCalled();
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
it("throws when directory exists but has no valid package", async () => {
|
|
470
|
-
const deps = makeMockDeps({});
|
|
471
|
-
const dc = mockDataContext();
|
|
472
|
-
deps.fs.exists.mockResolvedValue(true);
|
|
473
|
-
mockGetPackageInfo.mockResolvedValue({ name: "no-id-pkg" });
|
|
474
|
-
await expect((0, package_creator_1.createPackage)(dc, deps, { name: "bad-pkg", location: "/some/path" })).rejects.toThrow("does not contain a valid Peers package");
|
|
475
|
-
});
|
|
476
|
-
it("fills in the template's consts.ts and README, with the name as one string expression", async () => {
|
|
477
|
-
const template = {
|
|
478
|
-
"/packages/x/src/consts.ts": [
|
|
479
|
-
'export const packageId = "<package-id>";',
|
|
480
|
-
'export const packageName = "<package-name>";',
|
|
481
|
-
'export const contractId = "<contract-id>";',
|
|
482
|
-
'export const appScreenId = "<app-screen-id>";',
|
|
483
|
-
].join("\n"),
|
|
484
|
-
"/packages/x/README.md": "# <package-name>\n",
|
|
485
|
-
"/packages/x/src/ids.json": '{"packageName":"<package-name>","packageId":"<package-id>"}',
|
|
486
|
-
};
|
|
487
|
-
async function create(name) {
|
|
488
|
-
const deps = makeMockDeps({});
|
|
489
|
-
deps.fs.exists.mockImplementation(async (path) => path in template);
|
|
490
|
-
deps.fs.readFile.mockImplementation(async (path) => template[path]);
|
|
491
|
-
deps.fs.readJson.mockResolvedValue({ name: "template", peers: {} });
|
|
492
|
-
mockGroupDeviceVar.mockReturnValue(jest.fn());
|
|
493
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
494
|
-
packageVersion: { packageVersionId: "pv" },
|
|
495
|
-
loaded: undefined,
|
|
496
|
-
unchanged: false,
|
|
497
|
-
});
|
|
498
|
-
await (0, package_creator_1.createPackage)(mockDataContext(), deps, { name, location: "/packages/x" });
|
|
499
|
-
const written = (path) => deps.fs.writeFile.mock.calls.find((call) => call[0] === path)[1];
|
|
500
|
-
const consts = written("/packages/x/src/consts.ts");
|
|
501
|
-
const literal = /packageName = (.*);/.exec(consts)?.[1] ?? "";
|
|
502
|
-
return {
|
|
503
|
-
consts,
|
|
504
|
-
literal,
|
|
505
|
-
readme: written("/packages/x/README.md"),
|
|
506
|
-
ids: JSON.parse(written("/packages/x/src/ids.json")),
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
const plain = await create("My Widget");
|
|
510
|
-
expect(plain.literal).toBe('"My Widget"');
|
|
511
|
-
expect(plain.consts).toMatch(/packageId = "[a-z0-9]{25}";/);
|
|
512
|
-
expect(plain.consts).not.toContain("<");
|
|
513
|
-
expect(plain.readme).toBe("# My Widget\n");
|
|
514
|
-
expect((await create("Cash $& Carry")).readme).toBe("# Cash $& Carry\n");
|
|
515
|
-
// Quoted as Biome's formatter would, so a new package passes `npm run lint`.
|
|
516
|
-
for (const [name, literal] of [
|
|
517
|
-
["Mark's List", `"Mark's List"`],
|
|
518
|
-
['The "Best" List', `'The "Best" List'`],
|
|
519
|
-
[`Mark's "Best" \\ List`, `'Mark\\'s "Best" \\\\ List'`],
|
|
520
|
-
["Cash $& Carry", `"Cash $& Carry"`],
|
|
521
|
-
["Café 漢字 🥛", `"Café 漢字 🥛"`],
|
|
522
|
-
["Line\u2028and\u2029paragraph", `"Line\\u2028and\\u2029paragraph"`],
|
|
523
|
-
['Say "hi"\u2028twice', `'Say "hi"\\u2028twice'`],
|
|
524
|
-
["A <package-name> <package-id>", `"A <package-name> <package-id>"`],
|
|
525
|
-
]) {
|
|
526
|
-
const created = await create(name);
|
|
527
|
-
expect(created.literal).toBe(literal);
|
|
528
|
-
expect(new Function(`return ${created.literal};`)()).toBe(name);
|
|
529
|
-
expect(created.readme).toBe(`# ${name}\n`);
|
|
530
|
-
expect(created.ids.packageName).toBe(name);
|
|
531
|
-
expect(created.ids.packageId).toMatch(/^[a-z0-9]{25}$/);
|
|
532
|
-
}
|
|
533
|
-
for (const name of [
|
|
534
|
-
"List <!-- comments -->",
|
|
535
|
-
"List import( jokes",
|
|
536
|
-
"List import /* notes",
|
|
537
|
-
'List eval( "quoted" \\ 漢字\u2028',
|
|
538
|
-
]) {
|
|
539
|
-
const created = await create(name);
|
|
540
|
-
expect(created.literal).toMatch(/^String\(JSON.parse\(/);
|
|
541
|
-
expect(created.literal).not.toMatch(/<!--|-->|\b(?:import|eval)\s*(?:\(|\/[/*])/);
|
|
542
|
-
expect(new Function(`return ${created.literal};`)()).toBe(name);
|
|
543
|
-
expect(created.ids.packageName).toBe(name);
|
|
544
|
-
expect(created.readme).toBe(`# ${name}\n`);
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
it("uses direct clone (no caching) when custom templateRepo is provided", async () => {
|
|
548
|
-
const deps = makeMockDeps({});
|
|
549
|
-
const dc = mockDataContext();
|
|
550
|
-
deps.fs.exists.mockImplementation(async (path) => {
|
|
551
|
-
if (path === "/packages/my-pkg")
|
|
552
|
-
return false;
|
|
553
|
-
if (path.includes("consts.ts"))
|
|
554
|
-
return false;
|
|
555
|
-
return false;
|
|
556
|
-
});
|
|
557
|
-
deps.fs.readJson.mockResolvedValue({ name: "template", peers: {} });
|
|
558
|
-
const pvarSetter = jest.fn();
|
|
559
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
560
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
561
|
-
packageVersion: { packageVersionId: "pv" },
|
|
562
|
-
loaded: undefined,
|
|
563
|
-
unchanged: false,
|
|
564
|
-
});
|
|
565
|
-
await (0, package_creator_1.createPackage)(dc, deps, {
|
|
566
|
-
name: "My Pkg",
|
|
567
|
-
templateRepo: "https://example.com/custom-template.git",
|
|
568
|
-
});
|
|
569
|
-
// Custom template should clone directly to location (no cache, no cp -r)
|
|
570
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("git clone https://example.com/custom-template.git /packages/my-pkg");
|
|
571
|
-
const execCalls = deps.shell.exec.mock.calls.map((c) => c[0]);
|
|
572
|
-
expect(execCalls).not.toContain(expect.stringContaining("cp -r"));
|
|
573
|
-
expect(execCalls).not.toContain(expect.stringContaining(".peers-package-template"));
|
|
574
|
-
});
|
|
575
|
-
it("uses custom location when provided", async () => {
|
|
576
|
-
const deps = makeMockDeps({});
|
|
577
|
-
const dc = mockDataContext();
|
|
578
|
-
deps.fs.exists.mockResolvedValue(false);
|
|
579
|
-
deps.fs.readJson.mockResolvedValue({ name: "template", peers: {} });
|
|
580
|
-
const pvarSetter = jest.fn();
|
|
581
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
582
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
583
|
-
packageVersion: { packageVersionId: "pv" },
|
|
584
|
-
loaded: undefined,
|
|
585
|
-
unchanged: false,
|
|
586
|
-
});
|
|
587
|
-
await (0, package_creator_1.createPackage)(dc, deps, {
|
|
588
|
-
name: "My Pkg",
|
|
589
|
-
location: "/custom/my-special-location",
|
|
590
|
-
});
|
|
591
|
-
expect(deps.shell.exec).toHaveBeenCalledWith(expect.stringContaining("/custom/my-special-location"));
|
|
592
|
-
expect(pvarSetter).toHaveBeenCalledWith("/custom/my-special-location");
|
|
593
|
-
});
|
|
594
|
-
it("generates a signing keypair and stores it when personalContext is provided", async () => {
|
|
595
|
-
const deps = makeMockDeps({});
|
|
596
|
-
const dc = mockDataContext();
|
|
597
|
-
const personalCtx = mockDataContext();
|
|
598
|
-
deps.fs.exists.mockImplementation(async (path) => {
|
|
599
|
-
if (path.includes("consts.ts"))
|
|
600
|
-
return false;
|
|
601
|
-
return false;
|
|
602
|
-
});
|
|
603
|
-
deps.fs.readJson.mockResolvedValue({ name: "template", peers: {} });
|
|
604
|
-
const pvarSetter = jest.fn();
|
|
605
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
606
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
607
|
-
packageVersion: { packageVersionId: "pv" },
|
|
608
|
-
loaded: undefined,
|
|
609
|
-
unchanged: false,
|
|
610
|
-
});
|
|
611
|
-
await (0, package_creator_1.createPackage)(dc, deps, {
|
|
612
|
-
name: "Signed Pkg",
|
|
613
|
-
personalContext: personalCtx,
|
|
614
|
-
});
|
|
615
|
-
// Verify keypair was generated
|
|
616
|
-
expect(mockNewKeys).toHaveBeenCalled();
|
|
617
|
-
// Verify secret key was saved as a secret pvar in personal context
|
|
618
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledWith(expect.objectContaining({
|
|
619
|
-
name: expect.stringMatching(/^packageSigningKey_[a-z0-9]{25}$/),
|
|
620
|
-
scope: "user",
|
|
621
|
-
value: { value: generatedKeys.secretKey },
|
|
622
|
-
isSecret: true,
|
|
623
|
-
description: expect.stringContaining("Signed Pkg"),
|
|
624
|
-
}), { restoreIfDeleted: true });
|
|
625
|
-
// Verify publishPublicKey was set on the package record
|
|
626
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(dc, expect.objectContaining({
|
|
627
|
-
publishPublicKey: generatedKeys.publicKey,
|
|
628
|
-
}), expect.any(Object));
|
|
629
|
-
});
|
|
630
|
-
it("skips key generation when personalContext is not provided", async () => {
|
|
631
|
-
const deps = makeMockDeps({});
|
|
632
|
-
const dc = mockDataContext();
|
|
633
|
-
deps.fs.exists.mockImplementation(async (path) => {
|
|
634
|
-
if (path.includes("consts.ts"))
|
|
635
|
-
return false;
|
|
636
|
-
return false;
|
|
637
|
-
});
|
|
638
|
-
deps.fs.readJson.mockResolvedValue({ name: "template", peers: {} });
|
|
639
|
-
const pvarSetter = jest.fn();
|
|
640
|
-
mockGroupDeviceVar.mockReturnValue(pvarSetter);
|
|
641
|
-
mockInstallPackageFromBundles.mockResolvedValue({
|
|
642
|
-
packageVersion: { packageVersionId: "pv" },
|
|
643
|
-
loaded: undefined,
|
|
644
|
-
unchanged: false,
|
|
645
|
-
});
|
|
646
|
-
await (0, package_creator_1.createPackage)(dc, deps, { name: "No Key Pkg" });
|
|
647
|
-
// Should NOT call newKeys
|
|
648
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
649
|
-
// Should NOT save any pvar
|
|
650
|
-
expect(mockPersistentVarsSave).not.toHaveBeenCalled();
|
|
651
|
-
// publishPublicKey should be empty string
|
|
652
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(dc, expect.objectContaining({
|
|
653
|
-
publishPublicKey: "",
|
|
654
|
-
}), expect.any(Object));
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
describe("ensurePackageSigningKey", () => {
|
|
658
|
-
it("generates a key once when none exists", async () => {
|
|
659
|
-
const personalCtx = mockDataContext();
|
|
660
|
-
const publicKey = await (0, package_creator_1.ensurePackageSigningKey)({
|
|
661
|
-
personalContext: personalCtx,
|
|
662
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
663
|
-
packageName: "Test Pkg",
|
|
664
|
-
});
|
|
665
|
-
expect(publicKey).toBe(generatedKeys.publicKey);
|
|
666
|
-
expect(mockNewKeys).toHaveBeenCalledTimes(1);
|
|
667
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledTimes(1);
|
|
668
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledWith(expect.objectContaining({
|
|
669
|
-
persistentVarId: (0, utils_1.deterministicPvarId)("packageSigningKey_00mnkoyo7mizav6tseubjzr3a"),
|
|
670
|
-
value: { value: generatedKeys.secretKey },
|
|
671
|
-
description: `Signing key for package "Test Pkg"\npeers-package-signing-key:v1:00mnkoyo7mizav6tseubjzr3a:${generatedKeys.publicKey}`,
|
|
672
|
-
}), { restoreIfDeleted: true });
|
|
673
|
-
});
|
|
674
|
-
it("reuses an established publishPublicKey without generating a new key", async () => {
|
|
675
|
-
const personalCtx = mockDataContext();
|
|
676
|
-
const publicKey = await (0, package_creator_1.ensurePackageSigningKey)({
|
|
677
|
-
personalContext: personalCtx,
|
|
678
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
679
|
-
packageName: "Test Pkg",
|
|
680
|
-
existingPublishPublicKey: "established-key",
|
|
681
|
-
});
|
|
682
|
-
expect(publicKey).toBe("established-key");
|
|
683
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
684
|
-
expect(mockPersistentVarsSave).not.toHaveBeenCalled();
|
|
685
|
-
});
|
|
686
|
-
it("throws on an unrecoverable public/private key mismatch", async () => {
|
|
687
|
-
const { newKeys: realNewKeys } = jest.requireActual("../keys");
|
|
688
|
-
const realKeys = realNewKeys();
|
|
689
|
-
const otherKeys = realNewKeys();
|
|
690
|
-
const personalCtx = mockDataContext();
|
|
691
|
-
mockPersistentVarsFindOne.mockResolvedValue({
|
|
692
|
-
name: "packageSigningKey_00mnkoyo7mizav6tseubjzr3a",
|
|
693
|
-
value: { value: realKeys.secretKey },
|
|
694
|
-
isSecret: true,
|
|
695
|
-
});
|
|
696
|
-
await expect((0, package_creator_1.ensurePackageSigningKey)({
|
|
697
|
-
personalContext: personalCtx,
|
|
698
|
-
packageId: "00mnkoyo7mizav6tseubjzr3a",
|
|
699
|
-
packageName: "Test Pkg",
|
|
700
|
-
existingPublishPublicKey: otherKeys.publicKey,
|
|
701
|
-
})).rejects.toThrow("signing key mismatch");
|
|
702
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
703
|
-
});
|
|
704
|
-
});
|
|
705
|
-
describe("signing key recovery after uninstall", () => {
|
|
706
|
-
const packageId = "00mnkoyo7mizav6tseubjzr3a";
|
|
707
|
-
const marker = `peers-package-signing-key:v1:${packageId}:${generatedKeys.publicKey}`;
|
|
708
|
-
let record;
|
|
709
|
-
let deps;
|
|
710
|
-
let personalContext;
|
|
711
|
-
let target;
|
|
712
|
-
beforeEach(() => {
|
|
713
|
-
personalContext = mockDataContext();
|
|
714
|
-
target = mockDataContext();
|
|
715
|
-
record = {
|
|
716
|
-
persistentVarId: (0, utils_1.deterministicPvarId)(`packageSigningKey_${packageId}`),
|
|
717
|
-
name: `packageSigningKey_${packageId}`,
|
|
718
|
-
scope: "user",
|
|
719
|
-
isSecret: true,
|
|
720
|
-
value: { value: "encrypted-secret~nonce" },
|
|
721
|
-
description: 'Signing key for package "Test Pkg"',
|
|
722
|
-
modifiedAt: 123,
|
|
723
|
-
};
|
|
724
|
-
mockPersistentVarsFindOne.mockImplementation(async () => record);
|
|
725
|
-
mockPersistentVarsSave.mockImplementation(async (saved) => {
|
|
726
|
-
record = saved;
|
|
727
|
-
});
|
|
728
|
-
deps = makeMockDeps({ "/packages/test-pkg/package.json": "{}" });
|
|
729
|
-
mockGetPackageInfo.mockResolvedValue({ packageId, name: "test-pkg" });
|
|
730
|
-
mockGroupDeviceVar.mockReturnValue(jest.fn());
|
|
731
|
-
mockInstallPackageFromBundles.mockResolvedValue({ packageVersion: { packageId } });
|
|
732
|
-
});
|
|
733
|
-
async function importPackage(resolveSigningPublicKey) {
|
|
734
|
-
return (0, package_creator_1.createPackage)(target, deps, {
|
|
735
|
-
name: "Test Pkg",
|
|
736
|
-
personalContext,
|
|
737
|
-
resolveSigningPublicKey,
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
function expectNoWrites() {
|
|
741
|
-
expect(mockPersistentVarsSave).not.toHaveBeenCalled();
|
|
742
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
743
|
-
expect(mockSignAndSavePkg).not.toHaveBeenCalled();
|
|
744
|
-
expect(mockGroupDeviceVar).not.toHaveBeenCalled();
|
|
745
|
-
expect(mockInstallPackageFromBundles).not.toHaveBeenCalled();
|
|
746
|
-
}
|
|
747
|
-
it("recovers a cached public key with no Packages row or decryption callback", async () => {
|
|
748
|
-
record.description += `\n${marker}`;
|
|
749
|
-
await importPackage();
|
|
750
|
-
expect(mockSignAndSavePkg).toHaveBeenCalledWith(target, expect.objectContaining({ publishPublicKey: generatedKeys.publicKey }), expect.any(Object));
|
|
751
|
-
expect(mockPersistentVarsSave).not.toHaveBeenCalled();
|
|
752
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
753
|
-
});
|
|
754
|
-
it("recovers a legacy encrypted secret through the host and backfills only description once", async () => {
|
|
755
|
-
const original = { ...record };
|
|
756
|
-
const resolve = jest.fn(async () => generatedKeys.publicKey);
|
|
757
|
-
await importPackage(resolve);
|
|
758
|
-
expect(resolve).toHaveBeenCalledWith(original.value.value);
|
|
759
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledWith({
|
|
760
|
-
...original,
|
|
761
|
-
description: `${original.description}\n${marker}`,
|
|
762
|
-
});
|
|
763
|
-
await importPackage(resolve);
|
|
764
|
-
expect(mockPersistentVarsSave).toHaveBeenCalledTimes(1);
|
|
765
|
-
expect(record.value).toBe(original.value);
|
|
766
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
767
|
-
});
|
|
768
|
-
it("retains raw-secret hydration and backfills its public key without invoking the host", async () => {
|
|
769
|
-
record.value = { value: generatedKeys.secretKey };
|
|
770
|
-
const resolve = jest.fn();
|
|
771
|
-
await importPackage(resolve);
|
|
772
|
-
expect(resolve).not.toHaveBeenCalled();
|
|
773
|
-
expect(record.description).toContain(marker);
|
|
774
|
-
expect(record.value.value).toBe(generatedKeys.secretKey);
|
|
775
|
-
});
|
|
776
|
-
it.each([
|
|
777
|
-
"absent",
|
|
778
|
-
"throws",
|
|
779
|
-
"undefined",
|
|
780
|
-
"invalid",
|
|
781
|
-
])("fails safely when host recovery is %s", async (mode) => {
|
|
782
|
-
const resolve = mode === "absent"
|
|
783
|
-
? undefined
|
|
784
|
-
: jest.fn(async () => {
|
|
785
|
-
if (mode === "throws")
|
|
786
|
-
throw new Error(`sensitive ${record.value.value} ${generatedKeys.secretKey}`);
|
|
787
|
-
return mode === "invalid" ? "not-a-public-key" : undefined;
|
|
788
|
-
});
|
|
789
|
-
await expect(importPackage(resolve)).rejects.toThrow(`Package "Test Pkg" (${packageId}) has a signing secret pvar but no recoverable publishPublicKey, ` +
|
|
790
|
-
"and the secret could not be hydrated. Restore publishPublicKey or unlock the signing secret before importing.");
|
|
791
|
-
expectNoWrites();
|
|
792
|
-
});
|
|
793
|
-
it.each([
|
|
794
|
-
"established",
|
|
795
|
-
"cached",
|
|
796
|
-
])("uses the %s key when host decryption fails", async (source) => {
|
|
797
|
-
if (source === "cached")
|
|
798
|
-
record.description += `\n${marker}`;
|
|
799
|
-
else
|
|
800
|
-
mockGetPkg.mockResolvedValue({ publishPublicKey: generatedKeys.publicKey });
|
|
801
|
-
await importPackage(async () => {
|
|
802
|
-
throw new Error("decryption unavailable");
|
|
803
|
-
});
|
|
804
|
-
expect(record.description).toContain(marker);
|
|
805
|
-
expect(record.value.value).toBe("encrypted-secret~nonce");
|
|
806
|
-
expect(mockNewKeys).not.toHaveBeenCalled();
|
|
807
|
-
});
|
|
808
|
-
it.each([
|
|
809
|
-
"",
|
|
810
|
-
`peers-package-signing-key:v2:${packageId}:${generatedKeys.publicKey}`,
|
|
811
|
-
`peers-package-signing-key:v1:${(0, utils_1.newid)()}:${generatedKeys.publicKey}`,
|
|
812
|
-
`peers-package-signing-key:v1:${packageId}:invalid-key`,
|
|
813
|
-
`${marker}:extra`,
|
|
814
|
-
`prefix ${marker}`,
|
|
815
|
-
`${marker}\n${marker}`,
|
|
816
|
-
])("does not trust malformed or unrelated metadata: %s", async (description) => {
|
|
817
|
-
record.description = description;
|
|
818
|
-
await expect(importPackage()).rejects.toThrow("secret could not be hydrated");
|
|
819
|
-
expectNoWrites();
|
|
820
|
-
});
|
|
821
|
-
it("repairs malformed metadata after recovering a valid key", async () => {
|
|
822
|
-
record.description += `\npeers-package-signing-key:v1:${packageId}:invalid`;
|
|
823
|
-
await importPackage(async () => generatedKeys.publicKey);
|
|
824
|
-
expect(record.description).toBe(`Signing key for package "Test Pkg"\n${marker}`);
|
|
825
|
-
expect(record.value.value).toBe("encrypted-secret~nonce");
|
|
826
|
-
});
|
|
827
|
-
it.each([
|
|
828
|
-
"established/cache",
|
|
829
|
-
"raw/cache",
|
|
830
|
-
"host/cache",
|
|
831
|
-
"host/established",
|
|
832
|
-
])("rejects a %s mismatch before writes", async (source) => {
|
|
833
|
-
if (source.endsWith("cache"))
|
|
834
|
-
record.description += `\n${marker}`;
|
|
835
|
-
if (source.startsWith("established") || source.endsWith("established")) {
|
|
836
|
-
mockGetPkg.mockResolvedValue({ publishPublicKey: sourceKeys.publicKey });
|
|
837
|
-
}
|
|
838
|
-
if (source === "raw/cache")
|
|
839
|
-
record.value = { value: sourceKeys.secretKey };
|
|
840
|
-
const resolve = source.startsWith("host")
|
|
841
|
-
? async () => (source.endsWith("cache") ? sourceKeys.publicKey : generatedKeys.publicKey)
|
|
842
|
-
: undefined;
|
|
843
|
-
await expect(importPackage(resolve)).rejects.toThrow("signing key mismatch");
|
|
844
|
-
expectNoWrites();
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
describe("ensureTemplateCache", () => {
|
|
848
|
-
it("clones template when cache directory does not exist", async () => {
|
|
849
|
-
const deps = makeMockDeps({});
|
|
850
|
-
deps.fs.exists.mockResolvedValue(false);
|
|
851
|
-
const result = await (0, package_creator_1.ensureTemplateCache)(deps, "https://github.com/peers-app/peers-package-template.git");
|
|
852
|
-
expect(result.cachePath).toBe("/packages/.peers-package-template");
|
|
853
|
-
expect(result.warning).toBeUndefined();
|
|
854
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("git clone https://github.com/peers-app/peers-package-template.git /packages/.peers-package-template");
|
|
855
|
-
});
|
|
856
|
-
it("pulls latest when cache directory already exists", async () => {
|
|
857
|
-
const deps = makeMockDeps({});
|
|
858
|
-
deps.fs.exists.mockResolvedValue(true);
|
|
859
|
-
const result = await (0, package_creator_1.ensureTemplateCache)(deps, "https://github.com/peers-app/peers-package-template.git");
|
|
860
|
-
expect(result.cachePath).toBe("/packages/.peers-package-template");
|
|
861
|
-
expect(result.warning).toBeUndefined();
|
|
862
|
-
expect(deps.shell.exec).toHaveBeenCalledWith("git pull", {
|
|
863
|
-
cwd: "/packages/.peers-package-template",
|
|
864
|
-
});
|
|
865
|
-
// Should NOT have cloned
|
|
866
|
-
const execCalls = deps.shell.exec.mock.calls.map((c) => c[0]);
|
|
867
|
-
expect(execCalls).not.toContain(expect.stringContaining("git clone"));
|
|
868
|
-
});
|
|
869
|
-
it("returns an offline warning when pull cannot reach the remote", async () => {
|
|
870
|
-
const shellExec = jest.fn(async (cmd) => {
|
|
871
|
-
if (cmd === "git pull") {
|
|
872
|
-
throw new Error("fatal: unable to access 'https://github.com/peers-app/peers-package-template.git'");
|
|
873
|
-
}
|
|
874
|
-
return { stdout: "", stderr: "" };
|
|
875
|
-
});
|
|
876
|
-
const deps = makeMockDeps({}, shellExec);
|
|
877
|
-
deps.fs.exists.mockResolvedValue(true);
|
|
878
|
-
const result = await (0, package_creator_1.ensureTemplateCache)(deps, "https://github.com/peers-app/peers-package-template.git");
|
|
879
|
-
expect(result.cachePath).toBe("/packages/.peers-package-template");
|
|
880
|
-
expect(result.refreshFailure).toBe("offline");
|
|
881
|
-
expect(result.warning).toMatch(/could not be reached/i);
|
|
882
|
-
});
|
|
883
|
-
it("returns a could-not-refresh warning when pull fails for local git reasons", async () => {
|
|
884
|
-
const shellExec = jest.fn(async (cmd) => {
|
|
885
|
-
if (cmd === "git pull") {
|
|
886
|
-
throw new Error("error: Your local changes to the following files would be overwritten by merge:\n\t.gitignore");
|
|
887
|
-
}
|
|
888
|
-
return { stdout: "", stderr: "" };
|
|
889
|
-
});
|
|
890
|
-
const deps = makeMockDeps({}, shellExec);
|
|
891
|
-
deps.fs.exists.mockResolvedValue(true);
|
|
892
|
-
const result = await (0, package_creator_1.ensureTemplateCache)(deps, "https://github.com/peers-app/peers-package-template.git");
|
|
893
|
-
expect(result.cachePath).toBe("/packages/.peers-package-template");
|
|
894
|
-
expect(result.refreshFailure).toBe("could-not-refresh");
|
|
895
|
-
expect(result.warning).toMatch(/stale version/i);
|
|
896
|
-
expect(result.warning).toMatch(/overwritten by merge/i);
|
|
897
|
-
});
|
|
898
|
-
});
|
|
899
|
-
describe("classifyTemplatePullFailure", () => {
|
|
900
|
-
it("treats unreachable remotes as offline", () => {
|
|
901
|
-
expect((0, package_creator_1.classifyTemplatePullFailure)(new Error("fatal: unable to access remote"))).toBe("offline");
|
|
902
|
-
expect((0, package_creator_1.classifyTemplatePullFailure)(new Error("Could not resolve host: github.com"))).toBe("offline");
|
|
903
|
-
});
|
|
904
|
-
it("treats dirty trees and auth problems as could-not-refresh", () => {
|
|
905
|
-
expect((0, package_creator_1.classifyTemplatePullFailure)(new Error("Your local changes to the following files would be overwritten by merge"))).toBe("could-not-refresh");
|
|
906
|
-
expect((0, package_creator_1.classifyTemplatePullFailure)(new Error("Permission denied (publickey)"))).toBe("could-not-refresh");
|
|
907
|
-
});
|
|
908
|
-
});
|