test(compartment-mapper): Test duplicate compartment label ordering
ADD
packages/compartment-mapper/test/fixtures-stability/README.md
+This fixture creates an archive with more than one instance of the same version
+of the same dependency and ensures that these integrate into an archive in a
+suitable deterministic order, based on the lexical sort of the dependency name
+path to the package.
+
+0. 'a (a-v1.0.0-n0)
+1. 'a'a (a-v1.0.0-n1)
+2. 'a'a'dep (dep-v1.0.0-n0)
+3. 'a'b (b-v1.0.0) (only one version so no qualifier)
+4. 'a'b'dep (dep-v1.0.0-n2)
+5. 'a'dep (dep-v1.0.0-n1)

ADD
packages/compartment-mapper/test/fixtures-stability/a.js
+import a from 'a';
+import b from 'b';
+import dep from 'dep';
+
+export default [0, ...a, ...b, ...dep];

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/a/a.js
+import dep from 'dep';
+export default [1, ...dep];

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/a/node_modules/dep/dep.js
+export default [2];

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/a/node_modules/dep/package.json
+{
+ "name": "dep",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "./dep.js"
+}

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/a/package.json
+{
+ "name": "a",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "./a.js",
+ "dependencies": {
+ "dep": "^1.0.0"
+ }
+}

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/b/b.js
+import dep from 'dep';
+export default [3, ...dep];

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/b/node_modules/dep/dep.js
+export default [4];

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/b/node_modules/dep/package.json
+{
+ "name": "dep",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "./dep.js"
+}

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/b/package.json
+{
+ "name": "b",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "./b.js",
+ "dependencies": {
+ "dep": "^1.0.0"
+ }
+}

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/dep/dep.js
+export default [5];

ADD
packages/compartment-mapper/test/fixtures-stability/node_modules/dep/package.json
+{
+ "name": "dep",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "./dep.js"
+}

ADD
packages/compartment-mapper/test/fixtures-stability/package.json
+{
+ "name": "a",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "./a.js",
+ "dependencies": {
+ "dep": "^1.0.0",
+ "b": "^1.0.0",
+ "a": "^1.0.0"
+ }
+}

MODIFY
packages/compartment-mapper/test/test-retained.js
packages/compartment-mapper/test/test-retained.js
@@ -26,10 +26,10 @@ test('archives only contain compartments retained by modules', async t => {
const compartmentMapText = new TextDecoder().decode(compartmentMapBytes);
const compartmentMap = JSON.parse(compartmentMapText);
t.deepEqual(Object.keys(compartmentMap.compartments), [
- 'app-v1.0.0-n0',
- 'mk1-v1.0.0-n1',
- 'mk2-v1.0.0-n2',
+ 'app-v1.0.0',
+ 'mk1-v1.0.0',
+ 'mk2-v1.0.0',
// Notably absent:
- // 'sweep-v1.0.0-*',
+ // 'sweep-v1.0.0',
]);
});

ADD
packages/compartment-mapper/test/test-stability.js
+// @ts-check
+import 'ses';
+import test from 'ava';
+import { ZipReader } from '@endo/zip';
+import { makeArchive, parseArchive } from '../index.js';
+import { readPowers } from './scaffold.js';
+
+const fixture = new URL('fixtures-stability/a.js', import.meta.url).toString();
+
+test('order of duplicate name/version packages', async t => {
+ const bytes = await makeArchive(readPowers, fixture);
+
+ const reader = new ZipReader(bytes);
+ const compartmentMapBytes = reader.files.get('compartment-map.json').content;
+ const compartmentMapText = new TextDecoder().decode(compartmentMapBytes);
+ const compartmentMap = JSON.parse(compartmentMapText);
+
+ const actualOrder = Object.keys(compartmentMap.compartments);
+ t.log(actualOrder);
+
+ t.deepEqual(actualOrder, [
+ 'a-v1.0.0',
+ 'a-v1.0.0-n1',
+ 'b-v1.0.0',
+ 'dep-v1.0.0',
+ 'dep-v1.0.0-n1',
+ 'dep-v1.0.0-n2',
+ ]);
+
+ await t.notThrowsAsync(async () => {
+ const app = await parseArchive(bytes);
+ const {
+ namespace: { default: order },
+ } = await app.import();
+ t.log(order);
+ t.deepEqual(order, [0, 1, 2, 3, 4, 5]);
+ });
+});

test(compartment-mapper): Test duplicate compartment label ordering