@bevel-software/platform-core-backend 0.21.0 → 0.22.0
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/core/create-core-server.d.ts.map +1 -1
- package/dist/core/create-core-server.js +32 -2
- package/dist/core/create-core-server.js.map +1 -1
- package/dist/core/create-core-services.d.ts +13 -1
- package/dist/core/create-core-services.d.ts.map +1 -1
- package/dist/core/create-core-services.js +51 -5
- package/dist/core/create-core-services.js.map +1 -1
- package/dist/modules/access/access-requests.contract.d.ts +75 -0
- package/dist/modules/access/access-requests.contract.d.ts.map +1 -0
- package/dist/modules/access/access-requests.contract.js +20 -0
- package/dist/modules/access/access-requests.contract.js.map +1 -0
- package/dist/modules/access/access-requests.routes.d.ts +35 -0
- package/dist/modules/access/access-requests.routes.d.ts.map +1 -0
- package/dist/modules/access/access-requests.routes.js +237 -0
- package/dist/modules/access/access-requests.routes.js.map +1 -0
- package/dist/modules/access/access-requests.service.d.ts +123 -0
- package/dist/modules/access/access-requests.service.d.ts.map +1 -0
- package/dist/modules/access/access-requests.service.js +337 -0
- package/dist/modules/access/access-requests.service.js.map +1 -0
- package/dist/modules/access-model/access-grammar.d.ts +12 -0
- package/dist/modules/access-model/access-grammar.d.ts.map +1 -1
- package/dist/modules/access-model/access-grammar.js +24 -0
- package/dist/modules/access-model/access-grammar.js.map +1 -1
- package/dist/modules/auth/auth.service.d.ts +26 -1
- package/dist/modules/auth/auth.service.d.ts.map +1 -1
- package/dist/modules/auth/auth.service.js +11 -2
- package/dist/modules/auth/auth.service.js.map +1 -1
- package/dist/modules/github-app/github-app.client.d.ts +101 -0
- package/dist/modules/github-app/github-app.client.d.ts.map +1 -0
- package/dist/modules/github-app/github-app.client.js +222 -0
- package/dist/modules/github-app/github-app.client.js.map +1 -0
- package/dist/modules/github-app/github-app.connection.d.ts +102 -0
- package/dist/modules/github-app/github-app.connection.d.ts.map +1 -0
- package/dist/modules/github-app/github-app.connection.js +185 -0
- package/dist/modules/github-app/github-app.connection.js.map +1 -0
- package/dist/modules/github-app/github-app.routes.d.ts +59 -0
- package/dist/modules/github-app/github-app.routes.d.ts.map +1 -0
- package/dist/modules/github-app/github-app.routes.js +323 -0
- package/dist/modules/github-app/github-app.routes.js.map +1 -0
- package/dist/modules/github-app/index.d.ts +4 -0
- package/dist/modules/github-app/index.d.ts.map +1 -0
- package/dist/modules/github-app/index.js +4 -0
- package/dist/modules/github-app/index.js.map +1 -0
- package/dist/modules/kb-fs/remote-url.d.ts +22 -0
- package/dist/modules/kb-fs/remote-url.d.ts.map +1 -0
- package/dist/modules/kb-fs/remote-url.js +35 -0
- package/dist/modules/kb-fs/remote-url.js.map +1 -0
- package/dist/modules/plugins/join-proposals.d.ts +17 -5
- package/dist/modules/plugins/join-proposals.d.ts.map +1 -1
- package/dist/modules/plugins/join-proposals.js +76 -22
- package/dist/modules/plugins/join-proposals.js.map +1 -1
- package/dist/modules/plugins/join-requests.service.d.ts +111 -18
- package/dist/modules/plugins/join-requests.service.d.ts.map +1 -1
- package/dist/modules/plugins/join-requests.service.js +173 -29
- package/dist/modules/plugins/join-requests.service.js.map +1 -1
- package/dist/modules/plugins/plugins.routes.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.routes.js +3 -2
- package/dist/modules/plugins/plugins.routes.js.map +1 -1
- package/dist/modules/settings/deployment-settings.service.d.ts +22 -1
- package/dist/modules/settings/deployment-settings.service.d.ts.map +1 -1
- package/dist/modules/settings/deployment-settings.service.js +93 -4
- package/dist/modules/settings/deployment-settings.service.js.map +1 -1
- package/dist/modules/settings/managed-repository.d.ts +43 -0
- package/dist/modules/settings/managed-repository.d.ts.map +1 -0
- package/dist/modules/settings/managed-repository.js +60 -0
- package/dist/modules/settings/managed-repository.js.map +1 -0
- package/dist/modules/settings/repository-source.d.ts +128 -0
- package/dist/modules/settings/repository-source.d.ts.map +1 -0
- package/dist/modules/settings/repository-source.js +150 -0
- package/dist/modules/settings/repository-source.js.map +1 -0
- package/dist/modules/settings/setup.routes.d.ts +27 -4
- package/dist/modules/settings/setup.routes.d.ts.map +1 -1
- package/dist/modules/settings/setup.routes.js +187 -13
- package/dist/modules/settings/setup.routes.js.map +1 -1
- package/dist/modules/skills/skill-access-requests.routes.d.ts +6 -8
- package/dist/modules/skills/skill-access-requests.routes.d.ts.map +1 -1
- package/dist/modules/skills/skill-access-requests.routes.js +24 -63
- package/dist/modules/skills/skill-access-requests.routes.js.map +1 -1
- package/dist/modules/tool-helpers/tool-context.d.ts.map +1 -1
- package/dist/modules/tool-helpers/tool-context.js +15 -0
- package/dist/modules/tool-helpers/tool-context.js.map +1 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.d.ts.map +1 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.js +38 -2
- package/dist/modules/workflow/agent-tools/workflow.tools.js.map +1 -1
- package/dist/modules/workflow/git/git.service.d.ts +3 -1
- package/dist/modules/workflow/git/git.service.d.ts.map +1 -1
- package/dist/modules/workflow/git/git.service.js +17 -4
- package/dist/modules/workflow/git/git.service.js.map +1 -1
- package/dist/modules/workflow/git/node-git-runner.d.ts.map +1 -1
- package/dist/modules/workflow/git/node-git-runner.js +5 -0
- package/dist/modules/workflow/git/node-git-runner.js.map +1 -1
- package/dist/modules/workflow/git/pull-request.service.d.ts +45 -0
- package/dist/modules/workflow/git/pull-request.service.d.ts.map +1 -1
- package/dist/modules/workflow/git/pull-request.service.js +99 -0
- package/dist/modules/workflow/git/pull-request.service.js.map +1 -1
- package/dist/modules/workflow/workflow.routes.d.ts.map +1 -1
- package/dist/modules/workflow/workflow.routes.js +3 -1
- package/dist/modules/workflow/workflow.routes.js.map +1 -1
- package/dist/modules/workflow/workflow.service.d.ts +34 -7
- package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
- package/dist/modules/workflow/workflow.service.js +148 -48
- package/dist/modules/workflow/workflow.service.js.map +1 -1
- package/dist/modules/workspace/startup/kb-startup-runner.d.ts +66 -0
- package/dist/modules/workspace/startup/kb-startup-runner.d.ts.map +1 -1
- package/dist/modules/workspace/startup/kb-startup-runner.js +148 -0
- package/dist/modules/workspace/startup/kb-startup-runner.js.map +1 -1
- package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.service.js +17 -1
- package/dist/modules/workspace/workspace.service.js.map +1 -1
- package/dist/modules/workspace/workspace.tools.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.tools.js +28 -2
- package/dist/modules/workspace/workspace.tools.js.map +1 -1
- package/dist/shared/domain-errors.d.ts +39 -0
- package/dist/shared/domain-errors.d.ts.map +1 -1
- package/dist/shared/domain-errors.js +55 -0
- package/dist/shared/domain-errors.js.map +1 -1
- package/dist/shared/git.contract.d.ts +10 -0
- package/dist/shared/git.contract.d.ts.map +1 -1
- package/dist/shared/git.contract.js.map +1 -1
- package/package.json +3 -3
- package/src/core/create-core-server.ts +37 -1
- package/src/core/create-core-services.ts +65 -8
- package/src/modules/access/__tests__/access-requests.recut.test.ts +134 -0
- package/src/modules/access/__tests__/access-requests.routes.test.ts +610 -0
- package/src/modules/access/access-requests.contract.ts +93 -0
- package/src/modules/access/access-requests.routes.ts +286 -0
- package/src/modules/access/access-requests.service.ts +420 -0
- package/src/modules/access-model/access-grammar.ts +22 -0
- package/src/modules/auth/__tests__/auth.service.test.ts +38 -0
- package/src/modules/auth/auth.service.ts +28 -1
- package/src/modules/github-app/__tests__/github-app.test.ts +848 -0
- package/src/modules/github-app/github-app.client.ts +268 -0
- package/src/modules/github-app/github-app.connection.ts +204 -0
- package/src/modules/github-app/github-app.routes.ts +359 -0
- package/src/modules/github-app/index.ts +19 -0
- package/src/modules/kb-fs/__tests__/remote-url.test.ts +38 -0
- package/src/modules/kb-fs/remote-url.ts +35 -0
- package/src/modules/plugins/__tests__/join-proposals.test.ts +100 -19
- package/src/modules/plugins/__tests__/join-requests.service.test.ts +27 -11
- package/src/modules/plugins/__tests__/join-requests.settlement.test.ts +371 -0
- package/src/modules/plugins/__tests__/plugins.routes.test.ts +1 -1
- package/src/modules/plugins/join-proposals.ts +87 -19
- package/src/modules/plugins/join-requests.service.ts +199 -39
- package/src/modules/plugins/plugins.routes.ts +3 -2
- package/src/modules/settings/__tests__/repository-source.test.ts +191 -0
- package/src/modules/settings/__tests__/setup.routes.git-mode.test.ts +353 -0
- package/src/modules/settings/__tests__/setup.routes.github-app.test.ts +282 -0
- package/src/modules/settings/__tests__/setup.routes.managed-phase.test.ts +233 -0
- package/src/modules/settings/deployment-settings.service.ts +109 -3
- package/src/modules/settings/managed-repository.ts +68 -0
- package/src/modules/settings/repository-source.ts +197 -0
- package/src/modules/settings/setup.routes.ts +214 -10
- package/src/modules/skills/__tests__/skill-access-requests.routes.test.ts +5 -1
- package/src/modules/skills/skill-access-requests.routes.ts +25 -75
- package/src/modules/tool-helpers/tool-context.ts +15 -0
- package/src/modules/workflow/__tests__/apply-failure.test.ts +9 -1
- package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +159 -8
- package/src/modules/workflow/__tests__/workflow.service.update-from-target.test.ts +146 -40
- package/src/modules/workflow/agent-tools/__tests__/workflow.tools.test.ts +141 -1
- package/src/modules/workflow/agent-tools/workflow.tools.ts +49 -3
- package/src/modules/workflow/git/__tests__/git.service.pull.test.ts +121 -0
- package/src/modules/workflow/git/__tests__/pull-request.service.getPrDetail.test.ts +145 -2
- package/src/modules/workflow/git/__tests__/pull-request.service.viewer-can-delete.test.ts +166 -0
- package/src/modules/workflow/git/git.service.ts +25 -4
- package/src/modules/workflow/git/node-git-runner.ts +6 -0
- package/src/modules/workflow/git/pull-request.service.ts +119 -0
- package/src/modules/workflow/workflow.routes.ts +3 -1
- package/src/modules/workflow/workflow.service.ts +170 -52
- package/src/modules/workspace/__tests__/workspace.service.unknown-branch.test.ts +43 -0
- package/src/modules/workspace/__tests__/workspace.tools.branch-errors.test.ts +233 -7
- package/src/modules/workspace/__tests__/workspace.tools.test.ts +35 -3
- package/src/modules/workspace/startup/__tests__/kb-startup-runner.test.ts +211 -0
- package/src/modules/workspace/startup/kb-startup-runner.ts +159 -0
- package/src/modules/workspace/workspace.service.ts +17 -1
- package/src/modules/workspace/workspace.tools.ts +35 -0
- package/src/shared/domain-errors.ts +58 -0
- package/src/shared/git.contract.ts +10 -0
|
@@ -7,8 +7,10 @@ import {
|
|
|
7
7
|
type IWorkflowService,
|
|
8
8
|
} from '@bevel-software/platform-shared';
|
|
9
9
|
import { type WorkspaceService } from '../../workspace/workspace.service.js';
|
|
10
|
+
import type { IAccessControl } from '../../access/access-control.interface.js';
|
|
10
11
|
import { workspaceIdForBranch } from '../../../shared/workspace-id.js';
|
|
11
12
|
import { JoinRequestsService } from '../join-requests.service.js';
|
|
13
|
+
import { folderTarget } from '../../access/access-requests.contract.js';
|
|
12
14
|
import { testKbContext } from '../../../__tests__/kb-context.js';
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -44,7 +46,7 @@ function cr(over: Partial<ChangeRequest> = {}): ChangeRequest {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/** `byRef[ref]` is the access.md content at that ref (undefined ⇒ absent). */
|
|
47
|
-
function makeHarness(byRef: Record<string, string>) {
|
|
49
|
+
function makeHarness(byRef: Record<string, string>, holds: Record<string, unknown> = {}) {
|
|
48
50
|
const workspaceService = {
|
|
49
51
|
ensureRemotesFetched: vi.fn(async () => undefined),
|
|
50
52
|
readFileAtRef: vi.fn(async (_ws: string, ref: string, path: string) =>
|
|
@@ -55,7 +57,21 @@ function makeHarness(byRef: Record<string, string>) {
|
|
|
55
57
|
rejectChangeRequest: vi.fn(async () => ({ number: 7, state: 'closed' })),
|
|
56
58
|
deleteBranch: vi.fn(async () => undefined),
|
|
57
59
|
} as unknown as IWorkflowService;
|
|
58
|
-
|
|
60
|
+
// Nobody holds anything by default: every proposal stands on the file diff
|
|
61
|
+
// alone, which is what these cases are about.
|
|
62
|
+
const accessControl = {
|
|
63
|
+
canRead: vi.fn(async () => false),
|
|
64
|
+
canWrite: vi.fn(async () => false),
|
|
65
|
+
canOwner: vi.fn(async () => false),
|
|
66
|
+
canDownload: vi.fn(async () => false),
|
|
67
|
+
...holds,
|
|
68
|
+
} as unknown as IAccessControl;
|
|
69
|
+
return {
|
|
70
|
+
svc: new JoinRequestsService(workspaceService, workflow, testKbContext(), accessControl),
|
|
71
|
+
workflow,
|
|
72
|
+
workspaceService,
|
|
73
|
+
accessControl,
|
|
74
|
+
};
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
const refs = (branchMd: string | undefined, defaultMd = DEFAULT_MD) => ({
|
|
@@ -66,7 +82,7 @@ const refs = (branchMd: string | undefined, defaultMd = DEFAULT_MD) => ({
|
|
|
66
82
|
describe('JoinRequestsService.list', () => {
|
|
67
83
|
it('reports a request with its pending proposals, and leaves it open', async () => {
|
|
68
84
|
const h = makeHarness(refs(PROPOSING_MD));
|
|
69
|
-
const out = await h.svc.list('GTM', FOLDER, [cr()], ACTOR);
|
|
85
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
70
86
|
expect(out).toHaveLength(1);
|
|
71
87
|
expect(out[0]).toMatchObject({ number: 7, requesterName: 'Ali Baba' });
|
|
72
88
|
expect(out[0].proposals.map((p) => p.label)).toEqual(['Ali Baba']);
|
|
@@ -76,7 +92,7 @@ describe('JoinRequestsService.list', () => {
|
|
|
76
92
|
it('SETTLES a request whose proposals have all landed: closes it, deletes the branch, omits it', async () => {
|
|
77
93
|
// The grant is on the default branch now, so the branch adds nothing.
|
|
78
94
|
const h = makeHarness(refs(PROPOSING_MD, PROPOSING_MD));
|
|
79
|
-
const out = await h.svc.list('GTM', FOLDER, [cr()], ACTOR);
|
|
95
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
80
96
|
expect(out).toEqual([]);
|
|
81
97
|
expect(h.workflow.rejectChangeRequest).toHaveBeenCalledWith(
|
|
82
98
|
7,
|
|
@@ -114,7 +130,7 @@ describe('JoinRequestsService.list', () => {
|
|
|
114
130
|
new Error('gh down'),
|
|
115
131
|
);
|
|
116
132
|
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
117
|
-
await expect(h.svc.list('GTM', FOLDER, [cr()], ACTOR)).resolves.toEqual([]);
|
|
133
|
+
await expect(h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR)).resolves.toEqual([]);
|
|
118
134
|
expect(warn).toHaveBeenCalled();
|
|
119
135
|
warn.mockRestore();
|
|
120
136
|
});
|
|
@@ -125,7 +141,7 @@ describe('JoinRequestsService.list', () => {
|
|
|
125
141
|
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
126
142
|
// The request still settles (omitted from the list) — the leftover branch
|
|
127
143
|
// is cosmetic, and the failure is logged rather than swallowed.
|
|
128
|
-
await expect(h.svc.list('GTM', FOLDER, [cr()], ACTOR)).resolves.toEqual([]);
|
|
144
|
+
await expect(h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR)).resolves.toEqual([]);
|
|
129
145
|
expect(h.workflow.rejectChangeRequest).toHaveBeenCalled();
|
|
130
146
|
expect(warn).toHaveBeenCalledWith(expect.stringContaining('could not delete'));
|
|
131
147
|
warn.mockRestore();
|
|
@@ -142,10 +158,10 @@ describe('JoinRequestsService.list', () => {
|
|
|
142
158
|
[`origin/${DEFAULT_BRANCH}`]: DEFAULT_MD,
|
|
143
159
|
[`origin/${joinBranchFor(ALI, 'Finance!')}`]: DEFAULT_MD,
|
|
144
160
|
});
|
|
145
|
-
await expect(h.svc.list('finance', 'Plugins/finance', [other], ACTOR)).resolves.toEqual([]);
|
|
161
|
+
await expect(h.svc.list('finance', folderTarget('Plugins/finance'), [other], ACTOR)).resolves.toEqual([]);
|
|
146
162
|
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
147
163
|
expect(h.workflow.deleteBranch).not.toHaveBeenCalled();
|
|
148
|
-
await expect(h.svc.reconcile('finance', 'Plugins/finance', other, ACTOR)).resolves.toBe(false);
|
|
164
|
+
await expect(h.svc.reconcile('finance', folderTarget('Plugins/finance'), other, ACTOR)).resolves.toBe(false);
|
|
149
165
|
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
150
166
|
});
|
|
151
167
|
});
|
|
@@ -153,21 +169,21 @@ describe('JoinRequestsService.list', () => {
|
|
|
153
169
|
describe('JoinRequestsService.reconcile', () => {
|
|
154
170
|
it('settles and reports true once nothing is pending', async () => {
|
|
155
171
|
const h = makeHarness(refs(PROPOSING_MD, PROPOSING_MD));
|
|
156
|
-
await expect(h.svc.reconcile('GTM', FOLDER, cr(), ACTOR)).resolves.toBe(true);
|
|
172
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(true);
|
|
157
173
|
expect(h.workflow.rejectChangeRequest).toHaveBeenCalled();
|
|
158
174
|
expect(h.workflow.deleteBranch).toHaveBeenCalled();
|
|
159
175
|
});
|
|
160
176
|
|
|
161
177
|
it('leaves a request alone while proposals remain', async () => {
|
|
162
178
|
const h = makeHarness(refs(PROPOSING_MD));
|
|
163
|
-
await expect(h.svc.reconcile('GTM', FOLDER, cr(), ACTOR)).resolves.toBe(false);
|
|
179
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(false);
|
|
164
180
|
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
165
181
|
});
|
|
166
182
|
|
|
167
183
|
it('refuses a change request that is not this plugin\'s join branch', async () => {
|
|
168
184
|
const h = makeHarness(refs(PROPOSING_MD, PROPOSING_MD));
|
|
169
185
|
await expect(
|
|
170
|
-
h.svc.reconcile('GTM', FOLDER, cr({ branch: 'ali/some-draft' }), ACTOR),
|
|
186
|
+
h.svc.reconcile('GTM', folderTarget(FOLDER), cr({ branch: 'ali/some-draft' }), ACTOR),
|
|
171
187
|
).resolves.toBe(false);
|
|
172
188
|
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
173
189
|
});
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_BRANCH,
|
|
4
|
+
joinBranchFor,
|
|
5
|
+
type AuthUser,
|
|
6
|
+
type ChangeRequest,
|
|
7
|
+
type IWorkflowService,
|
|
8
|
+
} from '@bevel-software/platform-shared';
|
|
9
|
+
import { type WorkspaceService } from '../../workspace/workspace.service.js';
|
|
10
|
+
import type { IAccessControl } from '../../access/access-control.interface.js';
|
|
11
|
+
import { folderTarget } from '../../access/access-requests.contract.js';
|
|
12
|
+
import { JoinRequestsService } from '../join-requests.service.js';
|
|
13
|
+
import { spliceGrant } from '../../access-model/access-splice.js';
|
|
14
|
+
import { testKbContext } from '../../../__tests__/kb-context.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A request ends when the person it names HOLDS what it asked for — however
|
|
18
|
+
* they came to hold it.
|
|
19
|
+
*
|
|
20
|
+
* The file diff alone cannot see that. Owner covers Can edit without putting
|
|
21
|
+
* a `write:` line anywhere; a role or a group carries access without naming
|
|
22
|
+
* anybody; a grant on a parent folder never touches this file at all. Each of
|
|
23
|
+
* those leaves the branch proposing something no editor can usefully accept,
|
|
24
|
+
* and the request sits open forever. These are the cases that asking the
|
|
25
|
+
* resolver instead settles — including for the two Library request kinds,
|
|
26
|
+
* which go through exactly this service.
|
|
27
|
+
*/
|
|
28
|
+
const ALI = 'ali@bevel.software';
|
|
29
|
+
const FOLDER = 'Plugins/GTM';
|
|
30
|
+
const ACCESS_MD = `${FOLDER}/access.md`;
|
|
31
|
+
const ACTOR: AuthUser = { id: 'u-1', email: 'olga@bevel.software', name: 'Olga Ivanova' };
|
|
32
|
+
const BRANCH = joinBranchFor(ALI, 'GTM');
|
|
33
|
+
|
|
34
|
+
const base = (body: string) => `---\nread:\n - everyone\n---\n${body}`;
|
|
35
|
+
const DEFAULT_MD = base('read:\n - GTM Team\n');
|
|
36
|
+
const ASKS_WRITE = base(`read:\n - GTM Team\nwrite:\n - Ali Baba <${ALI}>\n`);
|
|
37
|
+
const ASKS_FOR_A_ROLE = base('read:\n - GTM Team\n - role/Analysts\n');
|
|
38
|
+
|
|
39
|
+
function cr(over: Partial<ChangeRequest> = {}): ChangeRequest {
|
|
40
|
+
return {
|
|
41
|
+
number: 7,
|
|
42
|
+
title: 'Access request: GTM',
|
|
43
|
+
author: { login: 'user-abc' },
|
|
44
|
+
authorId: 'hash-ali',
|
|
45
|
+
appAuthor: { name: 'Ali Baba' },
|
|
46
|
+
branch: BRANCH,
|
|
47
|
+
base: DEFAULT_BRANCH,
|
|
48
|
+
state: 'open',
|
|
49
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
50
|
+
touchedNodePaths: [ACCESS_MD],
|
|
51
|
+
review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
|
|
52
|
+
url: '/change-requests/7',
|
|
53
|
+
...over,
|
|
54
|
+
} as ChangeRequest;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function makeHarness(
|
|
58
|
+
branchMd: string | undefined,
|
|
59
|
+
holds: Partial<Record<'canRead' | 'canWrite' | 'canOwner' | 'canDownload', boolean>> = {},
|
|
60
|
+
/** Refs that only appear once a FORCED fetch has run — a branch just pushed. */
|
|
61
|
+
arrivesOnForcedFetch: string | undefined = undefined,
|
|
62
|
+
liveMd: string = DEFAULT_MD,
|
|
63
|
+
) {
|
|
64
|
+
const byRef: Record<string, string> = {
|
|
65
|
+
[`origin/${DEFAULT_BRANCH}`]: liveMd,
|
|
66
|
+
...(branchMd === undefined ? {} : { [`origin/${BRANCH}`]: branchMd }),
|
|
67
|
+
};
|
|
68
|
+
const fetches: { force: boolean }[] = [];
|
|
69
|
+
const workspaceService = {
|
|
70
|
+
ensureRemotesFetched: vi.fn(async (_ws: string, opts: { force?: boolean } = {}) => {
|
|
71
|
+
fetches.push({ force: !!opts.force });
|
|
72
|
+
if (opts.force && arrivesOnForcedFetch !== undefined) {
|
|
73
|
+
byRef[`origin/${BRANCH}`] = arrivesOnForcedFetch;
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
readFileAtRef: vi.fn(async (_ws: string, ref: string, p: string) => {
|
|
77
|
+
if (p !== ACCESS_MD) return null;
|
|
78
|
+
const text = byRef[ref];
|
|
79
|
+
// A ref this clone has not heard of is not an empty file — it throws,
|
|
80
|
+
// exactly as `git show` does for an unknown ref.
|
|
81
|
+
if (text === undefined) throw new Error(`unknown revision ${ref}`);
|
|
82
|
+
return text;
|
|
83
|
+
}),
|
|
84
|
+
} as unknown as WorkspaceService;
|
|
85
|
+
const workflow = {
|
|
86
|
+
rejectChangeRequest: vi.fn(async () => ({ number: 7, state: 'closed' })),
|
|
87
|
+
deleteBranch: vi.fn(async () => undefined),
|
|
88
|
+
} as unknown as IWorkflowService;
|
|
89
|
+
const asked: { verb: string; path: string; email: string }[] = [];
|
|
90
|
+
const answer = (verb: 'canRead' | 'canWrite' | 'canOwner' | 'canDownload') =>
|
|
91
|
+
vi.fn(async (_ws: string, email: string, path: string) => {
|
|
92
|
+
asked.push({ verb, path, email });
|
|
93
|
+
return holds[verb] ?? false;
|
|
94
|
+
});
|
|
95
|
+
const accessControl = {
|
|
96
|
+
canRead: answer('canRead'),
|
|
97
|
+
canWrite: answer('canWrite'),
|
|
98
|
+
canOwner: answer('canOwner'),
|
|
99
|
+
canDownload: answer('canDownload'),
|
|
100
|
+
} as unknown as IAccessControl;
|
|
101
|
+
return {
|
|
102
|
+
svc: new JoinRequestsService(workspaceService, workflow, testKbContext(), accessControl),
|
|
103
|
+
workflow,
|
|
104
|
+
asked,
|
|
105
|
+
fetches,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
describe('a request settles once the person holds what it asked for', () => {
|
|
110
|
+
it('settles a write request when Owner already covers it', async () => {
|
|
111
|
+
// `canWrite` is the resolver's own question, and owner folds into write —
|
|
112
|
+
// so an owner grant made in the dialog retires the Can edit request.
|
|
113
|
+
const h = makeHarness(ASKS_WRITE, { canWrite: true });
|
|
114
|
+
await expect(h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR)).resolves.toEqual([]);
|
|
115
|
+
expect(h.workflow.rejectChangeRequest).toHaveBeenCalled();
|
|
116
|
+
expect(h.workflow.deleteBranch).toHaveBeenCalledWith(expect.anything(), BRANCH, ACTOR);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('asks about the ITEM, not its rules file — a folder request is about the folder', async () => {
|
|
120
|
+
const h = makeHarness(ASKS_WRITE, { canWrite: true });
|
|
121
|
+
await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
122
|
+
expect(h.asked).toContainEqual({ verb: 'canWrite', path: FOLDER, email: ALI });
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('settles through a role or group the person has since joined', async () => {
|
|
126
|
+
// Nothing in the file names Ali, yet the resolver says he writes here:
|
|
127
|
+
// that is a role, a group, or a grant on a parent folder.
|
|
128
|
+
const h = makeHarness(ASKS_WRITE, { canWrite: true });
|
|
129
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(true);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('leaves the request open while the person still holds nothing', async () => {
|
|
133
|
+
const h = makeHarness(ASKS_WRITE);
|
|
134
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
135
|
+
expect(out).toHaveLength(1);
|
|
136
|
+
expect(out[0].proposals.map((p) => p.verb)).toEqual(['write']);
|
|
137
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('keeps today\'s literal rule for a proposal naming a ROLE', async () => {
|
|
141
|
+
// "Does this role hold read here" is not a question the per-person
|
|
142
|
+
// resolver answers, so a role proposal is settled by the live rules
|
|
143
|
+
// carrying it — never by what some person happens to hold.
|
|
144
|
+
const h = makeHarness(ASKS_FOR_A_ROLE, { canRead: true, canWrite: true, canOwner: true });
|
|
145
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
146
|
+
expect(out).toHaveLength(1);
|
|
147
|
+
expect(out[0].proposals.map((p) => p.label)).toEqual(['role/Analysts']);
|
|
148
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('leaves the request open when the resolver cannot answer', async () => {
|
|
152
|
+
const h = makeHarness(ASKS_WRITE);
|
|
153
|
+
const svc = h.svc as unknown as { accessControl: { canWrite: () => Promise<boolean> } };
|
|
154
|
+
svc.accessControl.canWrite = () => Promise.reject(new Error('resolver down'));
|
|
155
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
156
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
157
|
+
expect(out).toHaveLength(1);
|
|
158
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
159
|
+
warn.mockRestore();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('a branch that cannot be read settles nothing', () => {
|
|
164
|
+
/**
|
|
165
|
+
* The failure this guards against, in full: these reads go through
|
|
166
|
+
* `origin/<branch>` in the DEFAULT branch's clone, and that clone's fetch is
|
|
167
|
+
* throttled. A request opened seconds ago names a ref the clone has not
|
|
168
|
+
* heard of. Read as "the branch proposes nothing" — which is what an empty
|
|
169
|
+
* diff against a missing file looks like — the request is CLOSED, by
|
|
170
|
+
* nobody, before any editor has seen it, and the person is told their
|
|
171
|
+
* request was not accepted.
|
|
172
|
+
*
|
|
173
|
+
* So: a miss is retried behind a forced fetch, and a miss that survives that
|
|
174
|
+
* leaves the request exactly where it was.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
it('retries behind a FORCED fetch before believing a branch says nothing', async () => {
|
|
178
|
+
// Present on origin, absent from this clone's refs until it fetches.
|
|
179
|
+
const h = makeHarness(undefined, {}, ASKS_WRITE);
|
|
180
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
181
|
+
|
|
182
|
+
expect(h.fetches.some((f) => f.force)).toBe(true);
|
|
183
|
+
expect(out).toHaveLength(1);
|
|
184
|
+
expect(out[0].proposals.map((p) => p.verb)).toEqual(['write']);
|
|
185
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('leaves the request open — and unclosed — when the branch still cannot be read', async () => {
|
|
189
|
+
const h = makeHarness(undefined);
|
|
190
|
+
await expect(h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR)).resolves.toEqual([]);
|
|
191
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
192
|
+
expect(h.workflow.deleteBranch).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('reconcile refuses to settle one it could not read', async () => {
|
|
196
|
+
const h = makeHarness(undefined);
|
|
197
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(false);
|
|
198
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('still settles a branch it DID read that proposes nothing', async () => {
|
|
202
|
+
// The distinction has to cut both ways, or nothing would ever retire.
|
|
203
|
+
const h = makeHarness(DEFAULT_MD);
|
|
204
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(true);
|
|
205
|
+
expect(h.workflow.rejectChangeRequest).toHaveBeenCalled();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('a person the rules explicitly deny', () => {
|
|
210
|
+
/**
|
|
211
|
+
* `ARTest5`-shaped rules: read granted, write DENIED, and the branch
|
|
212
|
+
* proposing the write anyway. The resolver says that person cannot write
|
|
213
|
+
* (verified against the real one), so their proposal is unmet and must
|
|
214
|
+
* survive to reach an editor — "Accept … includes a person the rules
|
|
215
|
+
* explicitly deny" is unreachable otherwise, and the requester is told a
|
|
216
|
+
* refusal nobody made.
|
|
217
|
+
*/
|
|
218
|
+
const DENIED_MD = base(`read:\n - Ali Baba <${ALI}>\nwrite:\n - deny Ali Baba <${ALI}>\n`);
|
|
219
|
+
const ASKS_DESPITE_DENY = base(
|
|
220
|
+
`read:\n - Ali Baba <${ALI}>\nwrite:\n - deny Ali Baba <${ALI}>\n - Ali Baba <${ALI}>\n`,
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
it('keeps their proposal, so an editor can still accept it', async () => {
|
|
224
|
+
// Live DENIES the write; the branch adds the grant beside the deny, which
|
|
225
|
+
// is exactly the text the dialog's own grant writes for this person.
|
|
226
|
+
const h = makeHarness(ASKS_DESPITE_DENY, { canRead: true, canWrite: false }, undefined, DENIED_MD);
|
|
227
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
228
|
+
expect(out).toHaveLength(1);
|
|
229
|
+
expect(out[0].proposals.map((p) => p.verb)).toEqual(['write']);
|
|
230
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('retires it once the grant has landed and the resolver says they write', async () => {
|
|
234
|
+
// What Accept does: a same-scope grant beats a same-scope deny, so the
|
|
235
|
+
// resolver then reports write and the request has nothing left to ask.
|
|
236
|
+
const h = makeHarness(ASKS_DESPITE_DENY, { canWrite: true }, undefined, DENIED_MD);
|
|
237
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(true);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('a stale ref must not be mistaken for a finished request', () => {
|
|
242
|
+
/**
|
|
243
|
+
* The nastier half of the same hazard. Here the branch's ref RESOLVES — it
|
|
244
|
+
* is simply a few seconds behind, pointing at the commit before the
|
|
245
|
+
* proposal was pushed. That reads as a file identical to live, which is an
|
|
246
|
+
* empty diff, which looks exactly like a request whose grants have all
|
|
247
|
+
* landed. Nothing about it looks like a failure, and the request is closed.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/** Stale: the branch answers with live's own text until a forced fetch. */
|
|
251
|
+
const staleHarness = () => makeHarness(DEFAULT_MD, {}, ASKS_WRITE);
|
|
252
|
+
|
|
253
|
+
it('does not settle a request whose proposal only shows after a fresh fetch', async () => {
|
|
254
|
+
const h = staleHarness();
|
|
255
|
+
const out = await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
256
|
+
|
|
257
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
258
|
+
expect(h.workflow.deleteBranch).not.toHaveBeenCalled();
|
|
259
|
+
// And having fetched, it reports the proposal rather than nothing.
|
|
260
|
+
expect(out).toHaveLength(1);
|
|
261
|
+
expect(out[0].proposals.map((p) => p.verb)).toEqual(['write']);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('reconcile refuses to settle it either', async () => {
|
|
265
|
+
const h = staleHarness();
|
|
266
|
+
await expect(h.svc.reconcile('GTM', folderTarget(FOLDER), cr(), ACTOR)).resolves.toBe(false);
|
|
267
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('confirms with a FORCED fetch before closing anything', async () => {
|
|
271
|
+
const h = makeHarness(DEFAULT_MD);
|
|
272
|
+
await h.svc.list('GTM', folderTarget(FOLDER), [cr()], ACTOR);
|
|
273
|
+
expect(h.fetches.some((f) => f.force)).toBe(true);
|
|
274
|
+
// Genuinely finished — the confirming read agrees, so it closes.
|
|
275
|
+
expect(h.workflow.rejectChangeRequest).toHaveBeenCalled();
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe('a request whose target is a FILE', () => {
|
|
280
|
+
/**
|
|
281
|
+
* The staging failure, at the level it happened. Every file-target request
|
|
282
|
+
* self-closed on the editors' FIRST listing: the listing answered
|
|
283
|
+
* `{"requests":[]}` and closed the change request in the same call, and the
|
|
284
|
+
* requester's status dropped to "none". Nobody had seen the line.
|
|
285
|
+
*
|
|
286
|
+
* A file's rules are its own frontmatter, and `spliceGrant` writes one grant
|
|
287
|
+
* there as a scalar — the same bytes the dialog's ordinary grant writes, and
|
|
288
|
+
* the resolver honours them. Read with the folder grammar it is a parse
|
|
289
|
+
* error, which yielded no grants, which reads as a finished request.
|
|
290
|
+
*
|
|
291
|
+
* So this exercises the real splice output against the real reader, with the
|
|
292
|
+
* target the request was actually made about.
|
|
293
|
+
*/
|
|
294
|
+
const FILE = 'Plugins/GTM/page.md';
|
|
295
|
+
const LIVE_FILE = '---\nnodeType: "[Note](../NodeTypes/Note.md)"\n---\n# Page\n\nbody\n';
|
|
296
|
+
const fileTarget = { path: FILE, kind: 'file' as const };
|
|
297
|
+
|
|
298
|
+
/** Exactly what the request opener writes onto the branch for a file. */
|
|
299
|
+
const asksWrite = spliceGrant(
|
|
300
|
+
LIVE_FILE,
|
|
301
|
+
'write',
|
|
302
|
+
{ kind: 'user', email: ALI, displayName: 'Ali Baba' },
|
|
303
|
+
{ allowScalar: true, target: 'node' },
|
|
304
|
+
).text;
|
|
305
|
+
|
|
306
|
+
/** The harness above is keyed on an access.md; this one answers for a file. */
|
|
307
|
+
function fileHarness(branchText: string, holds: Record<string, boolean> = {}) {
|
|
308
|
+
const byRef: Record<string, string> = {
|
|
309
|
+
[`origin/${DEFAULT_BRANCH}`]: LIVE_FILE,
|
|
310
|
+
[`origin/${BRANCH}`]: branchText,
|
|
311
|
+
};
|
|
312
|
+
const workspaceService = {
|
|
313
|
+
ensureRemotesFetched: vi.fn(async () => undefined),
|
|
314
|
+
readFileAtRef: vi.fn(async (_ws: string, ref: string, p: string) => {
|
|
315
|
+
if (p !== FILE) throw new Error(`unexpected path ${p}`);
|
|
316
|
+
const text = byRef[ref];
|
|
317
|
+
if (text === undefined) throw new Error(`unknown revision ${ref}`);
|
|
318
|
+
return text;
|
|
319
|
+
}),
|
|
320
|
+
} as unknown as WorkspaceService;
|
|
321
|
+
const workflow = {
|
|
322
|
+
rejectChangeRequest: vi.fn(async () => ({ number: 7, state: 'closed' })),
|
|
323
|
+
deleteBranch: vi.fn(async () => undefined),
|
|
324
|
+
} as unknown as IWorkflowService;
|
|
325
|
+
const answer = (verb: string) => vi.fn(async () => holds[verb] ?? false);
|
|
326
|
+
const accessControl = {
|
|
327
|
+
canRead: answer('canRead'),
|
|
328
|
+
canWrite: answer('canWrite'),
|
|
329
|
+
canOwner: answer('canOwner'),
|
|
330
|
+
canDownload: answer('canDownload'),
|
|
331
|
+
} as unknown as IAccessControl;
|
|
332
|
+
return {
|
|
333
|
+
svc: new JoinRequestsService(workspaceService, workflow, testKbContext(), accessControl),
|
|
334
|
+
workflow,
|
|
335
|
+
workspaceService,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
it('reads the file\'s OWN frontmatter, so the request survives the first listing', async () => {
|
|
340
|
+
const h = fileHarness(asksWrite);
|
|
341
|
+
const out = await h.svc.list('GTM', fileTarget, [cr()], ACTOR);
|
|
342
|
+
|
|
343
|
+
expect(out).toHaveLength(1);
|
|
344
|
+
expect(out[0].proposals.map((p) => p.verb)).toEqual(['write']);
|
|
345
|
+
expect(h.workflow.rejectChangeRequest).not.toHaveBeenCalled();
|
|
346
|
+
expect(h.workflow.deleteBranch).not.toHaveBeenCalled();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('reads the FILE itself, never an access.md beside it', async () => {
|
|
350
|
+
// A request on a file changes only that file's rules, so the only path it
|
|
351
|
+
// may read is the file. The harness throws on anything else.
|
|
352
|
+
const h = fileHarness(asksWrite);
|
|
353
|
+
await h.svc.list('GTM', fileTarget, [cr()], ACTOR);
|
|
354
|
+
const paths = (h.workspaceService.readFileAtRef as ReturnType<typeof vi.fn>).mock.calls.map(
|
|
355
|
+
(c) => c[2],
|
|
356
|
+
);
|
|
357
|
+
expect(new Set(paths)).toEqual(new Set([FILE]));
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('retires it once the person holds the level on the file', async () => {
|
|
361
|
+
const h = fileHarness(asksWrite, { canWrite: true });
|
|
362
|
+
await expect(h.svc.reconcile('GTM', fileTarget, cr(), ACTOR)).resolves.toBe(true);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('retires it once the grant has landed on live', async () => {
|
|
366
|
+
const h = fileHarness(asksWrite);
|
|
367
|
+
const byRef = h.workspaceService.readFileAtRef as ReturnType<typeof vi.fn>;
|
|
368
|
+
byRef.mockImplementation(async () => asksWrite); // both refs carry it now
|
|
369
|
+
await expect(h.svc.reconcile('GTM', fileTarget, cr(), ACTOR)).resolves.toBe(true);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
@@ -830,7 +830,7 @@ describe('/api/plugins routes', () => {
|
|
|
830
830
|
expect(await res.json()).toEqual({ requests: [] });
|
|
831
831
|
expect(h.joinRequests.list).toHaveBeenCalledWith(
|
|
832
832
|
'GTM',
|
|
833
|
-
'Plugins/GTM',
|
|
833
|
+
{ path: 'Plugins/GTM', kind: 'folder' },
|
|
834
834
|
expect.anything(),
|
|
835
835
|
expect.objectContaining({ email: ALI }),
|
|
836
836
|
);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
KNOWN_VERBS,
|
|
3
|
+
ownAccessReadable,
|
|
3
4
|
parseAccessFile,
|
|
5
|
+
parseOwnAccessEntries,
|
|
4
6
|
type ParsedEntry,
|
|
5
7
|
type Verb,
|
|
6
8
|
} from '../access-model/access-grammar.js';
|
|
9
|
+
import type { TargetKind } from '../access/access-mutation.service.js';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* What a join branch is PROPOSING, relative to the default branch.
|
|
@@ -50,23 +53,75 @@ function identityOf(entry: ParsedEntry): string {
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
|
-
*
|
|
56
|
+
* The per-verb entries one copy of an item's rules declares, or null when the
|
|
57
|
+
* text could not be read as rules at all.
|
|
54
58
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
59
|
+
* THE GRAMMAR FOLLOWS THE ITEM, because there are two of them and the
|
|
60
|
+
* resolver picks by item as well:
|
|
61
|
+
*
|
|
62
|
+
* folder a `access.md`, whose folder rules are a BODY of `verb:` block
|
|
63
|
+
* lists — `parseAccessFile`, which fails the whole file if a verb
|
|
64
|
+
* is not a list.
|
|
65
|
+
* file the node's OWN frontmatter — `parseOwnAccessEntries`, which also
|
|
66
|
+
* accepts the single-value scalar form (`write: Rita <r@x.io>`),
|
|
67
|
+
* ignores non-access keys like `nodeType:`, and drops a bad entry
|
|
68
|
+
* rather than failing the file.
|
|
69
|
+
*
|
|
70
|
+
* Reading a file's frontmatter with the FOLDER grammar is what broke every
|
|
71
|
+
* request whose target was a file: `spliceGrant` writes one grant into a
|
|
72
|
+
* node's frontmatter as exactly that scalar — the same bytes the dialog's own
|
|
73
|
+
* grant writes, which the resolver honours — and the folder grammar rejects it
|
|
74
|
+
* with "'write:' must be a list", failing the parse, yielding no grants, which
|
|
75
|
+
* reads as a branch with nothing left to propose. The request was then closed
|
|
76
|
+
* on the editors' first listing, before anyone had seen it.
|
|
77
|
+
*
|
|
78
|
+
* Null is reserved for "could not be read": a folder `access.md` that does
|
|
79
|
+
* not parse, or a file whose frontmatter is broken (never closed, or not a
|
|
80
|
+
* mapping). A file with no frontmatter, or with frontmatter naming no verb,
|
|
81
|
+
* is perfectly readable and simply grants nothing. The file grammar's own
|
|
82
|
+
* null does not tell those apart, so the question is asked separately: a
|
|
83
|
+
* broken block read as "grants nothing" would close the request on a
|
|
84
|
+
* reading that failed, the same mistake by another door.
|
|
60
85
|
*/
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
function entriesOf(
|
|
87
|
+
text: string,
|
|
88
|
+
path: string,
|
|
89
|
+
kind: TargetKind,
|
|
90
|
+
): Record<Verb, ParsedEntry[]> | null {
|
|
91
|
+
if (kind === 'file') {
|
|
92
|
+
return parseOwnAccessEntries(text) ?? (ownAccessReadable(text) ? emptyGrants() : null);
|
|
93
|
+
}
|
|
65
94
|
const parsed = parseAccessFile(text, path);
|
|
66
|
-
|
|
95
|
+
return parsed.ok ? parsed.file.entries : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function emptyGrants(): Record<Verb, ParsedEntry[]> {
|
|
99
|
+
const out = {} as Record<Verb, ParsedEntry[]>;
|
|
100
|
+
for (const verb of KNOWN_VERBS) out[verb] = [];
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** An index that grants nothing — the baseline a copy nobody could read stands in as. */
|
|
105
|
+
function emptyIndex(): Map<Verb, Map<string, ParsedEntry>> {
|
|
106
|
+
return new Map(KNOWN_VERBS.map((verb) => [verb, new Map<string, ParsedEntry>()]));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Grants only, indexed by canonical identity, from one copy of the rules.
|
|
111
|
+
* Null in, null out — an unreadable copy is not an empty one.
|
|
112
|
+
*/
|
|
113
|
+
function grantsByVerb(
|
|
114
|
+
text: string | null,
|
|
115
|
+
path: string,
|
|
116
|
+
kind: TargetKind,
|
|
117
|
+
): Map<Verb, Map<string, ParsedEntry>> | null {
|
|
118
|
+
if (text === null) return null;
|
|
119
|
+
const entries = entriesOf(text, path, kind);
|
|
120
|
+
if (entries === null) return null;
|
|
121
|
+
const out = emptyIndex();
|
|
67
122
|
for (const verb of KNOWN_VERBS) {
|
|
68
123
|
const byId = out.get(verb)!;
|
|
69
|
-
for (const entry of
|
|
124
|
+
for (const entry of entries[verb]) {
|
|
70
125
|
if (entry.deny) continue;
|
|
71
126
|
byId.set(identityOf(entry), entry);
|
|
72
127
|
}
|
|
@@ -75,19 +130,32 @@ function grantsByVerb(text: string | null, path: string): Map<Verb, Map<string,
|
|
|
75
130
|
}
|
|
76
131
|
|
|
77
132
|
/**
|
|
78
|
-
* The grants `branchText` adds over `defaultText` — the proposals
|
|
79
|
-
* can accept. Empty ⇒ the branch's rules are a subset of the default's
|
|
133
|
+
* The grants `branchText` adds over `defaultText` — the proposals an editor
|
|
134
|
+
* can accept. Empty ⇒ the branch's rules are a subset of the default's, which
|
|
135
|
+
* is the settled state.
|
|
136
|
+
*
|
|
137
|
+
* NULL when the branch's own copy is absent or unreadable, which is a
|
|
138
|
+
* different fact entirely and the one this surface keeps getting wrong: an
|
|
139
|
+
* empty answer closes somebody's request, so it has to mean "the branch asks
|
|
140
|
+
* for nothing more", never "the branch would not tell us".
|
|
141
|
+
*
|
|
142
|
+
* An unreadable DEFAULT copy stays what it was — every branch grant looks
|
|
143
|
+
* incoming. That is the safe direction on that side: an editor is shown
|
|
144
|
+
* proposals to consider rather than having them swallowed by a baseline
|
|
145
|
+
* nobody could read.
|
|
80
146
|
*
|
|
81
|
-
* `path`
|
|
82
|
-
*
|
|
147
|
+
* `path` labels parse errors; both texts are the same file at two refs, and
|
|
148
|
+
* `kind` says which grammar that file is written in.
|
|
83
149
|
*/
|
|
84
150
|
export function pendingProposals(
|
|
85
151
|
branchText: string | null,
|
|
86
152
|
defaultText: string | null,
|
|
87
153
|
path: string,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
154
|
+
kind: TargetKind,
|
|
155
|
+
): JoinProposal[] | null {
|
|
156
|
+
const branch = grantsByVerb(branchText, path, kind);
|
|
157
|
+
if (branch === null) return null;
|
|
158
|
+
const base = grantsByVerb(defaultText, path, kind) ?? emptyIndex();
|
|
91
159
|
const out: JoinProposal[] = [];
|
|
92
160
|
for (const verb of KNOWN_VERBS) {
|
|
93
161
|
const baseIds = base.get(verb)!;
|