Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

1.7 KB
Raw Blame
import { test } from "node:test";
import assert from "node:assert/strict";
import { createCanManageScope, createManagesArtifactHome } from "../src/resolution/scope-membership.ts";

const alpha = new Set(["[email protected]", "[email protected]"]);
const deps = {
  teams: { isMember: async (principalId: string, teamId: string) => teamId === "alpha" && alpha.has(principalId) },
  identity: {
    classify: (principalId: string) => ({
      type: principalId.startsWith("ext") ? ("external" as const) : ("internal" as const),
    }),
  },
};

test("a team-owned artifact is managed by the team's current members, not only its creator", async () => {
  const manages = createManagesArtifactHome(deps as never, createCanManageScope(deps as never));
  assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), true);
  assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), true);
});

test("a team-owned artifact is not manageable by non-members, including a creator who is no longer on the team", async () => {
  const manages = createManagesArtifactHome(deps as never, createCanManageScope(deps as never));
  assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
  assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
  assert.equal(await manages("team:other", "[email protected]", "[email protected]"), false);
  assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
});

test("without a team store, team-owned artifacts stay unmanageable (fails closed)", async () => {
  const noTeams = { identity: deps.identity };
  const manages = createManagesArtifactHome(noTeams as never, createCanManageScope(noTeams as never));
  assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
});