@leed-ai/git-gateway-contract 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +50 -2
- package/dist/behaviour/assertions.d.ts +23 -0
- package/dist/behaviour/assertions.js +56 -0
- package/dist/behaviour/assertions.js.map +1 -0
- package/dist/behaviour/behaviour-case.d.ts +19 -0
- package/dist/behaviour/behaviour-case.js +12 -0
- package/dist/behaviour/behaviour-case.js.map +1 -0
- package/dist/behaviour/behaviour-suite.d.ts +30 -0
- package/dist/behaviour/behaviour-suite.js +50 -0
- package/dist/behaviour/behaviour-suite.js.map +1 -0
- package/dist/behaviour/commit-action-cases.d.ts +4 -0
- package/dist/behaviour/commit-action-cases.js +342 -0
- package/dist/behaviour/commit-action-cases.js.map +1 -0
- package/dist/behaviour/commit-write-cases.d.ts +4 -0
- package/dist/behaviour/commit-write-cases.js +234 -0
- package/dist/behaviour/commit-write-cases.js.map +1 -0
- package/dist/behaviour/fixtures.d.ts +29 -0
- package/dist/behaviour/fixtures.js +83 -0
- package/dist/behaviour/fixtures.js.map +1 -0
- package/dist/behaviour/lifecycle-cases.d.ts +4 -0
- package/dist/behaviour/lifecycle-cases.js +158 -0
- package/dist/behaviour/lifecycle-cases.js.map +1 -0
- package/dist/behaviour/promote-cases.d.ts +4 -0
- package/dist/behaviour/promote-cases.js +122 -0
- package/dist/behaviour/promote-cases.js.map +1 -0
- package/dist/behaviour/read-cases.d.ts +4 -0
- package/dist/behaviour/read-cases.js +248 -0
- package/dist/behaviour/read-cases.js.map +1 -0
- package/dist/behaviour/sync-cases.d.ts +4 -0
- package/dist/behaviour/sync-cases.js +205 -0
- package/dist/behaviour/sync-cases.js.map +1 -0
- package/dist/clock-B3MlpmVY.d.ts +10 -0
- package/dist/commit-BEZmeAOl.d.ts +23 -0
- package/dist/file-map-CxUveLWz.d.ts +18 -0
- package/dist/gateway-config-oVsdTEeK.d.ts +39 -0
- package/dist/gateway-error-body-BWzZFAQI.d.ts +214 -0
- package/dist/gateway-error.d.ts +30 -0
- package/dist/gateway-error.js +63 -0
- package/dist/gateway-error.js.map +1 -0
- package/dist/git-gateway-VA9Tc5tn.d.ts +358 -0
- package/dist/git-gateway.d.ts +2 -0
- package/dist/git-gateway.js +65 -0
- package/dist/git-gateway.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.js +18 -0
- package/dist/health.js.map +1 -0
- package/dist/history-CqvHaUE-.d.ts +20 -0
- package/dist/package-name.d.ts +3 -0
- package/dist/package-name.js +6 -0
- package/dist/package-name.js.map +1 -0
- package/dist/proxy/audit-event.d.ts +61 -0
- package/dist/proxy/audit-event.js +97 -0
- package/dist/proxy/audit-event.js.map +1 -0
- package/dist/proxy/branch-rule.d.ts +72 -0
- package/dist/proxy/branch-rule.js +106 -0
- package/dist/proxy/branch-rule.js.map +1 -0
- package/dist/proxy/gateway-hooks.d.ts +58 -0
- package/dist/proxy/gateway-hooks.js +0 -0
- package/dist/proxy/git-operation.d.ts +17 -0
- package/dist/proxy/git-operation.js +32 -0
- package/dist/proxy/git-operation.js.map +1 -0
- package/dist/proxy/policy-result.d.ts +51 -0
- package/dist/proxy/policy-result.js +90 -0
- package/dist/proxy/policy-result.js.map +1 -0
- package/dist/proxy/principal.d.ts +18 -0
- package/dist/proxy/principal.js +32 -0
- package/dist/proxy/principal.js.map +1 -0
- package/dist/proxy/push-policy-result.d.ts +34 -0
- package/dist/proxy/push-policy-result.js +48 -0
- package/dist/proxy/push-policy-result.js.map +1 -0
- package/dist/proxy/push-policy.d.ts +146 -0
- package/dist/proxy/push-policy.js +112 -0
- package/dist/proxy/push-policy.js.map +1 -0
- package/dist/proxy/request-credential.d.ts +22 -0
- package/dist/proxy/request-credential.js +46 -0
- package/dist/proxy/request-credential.js.map +1 -0
- package/dist/proxy/smart-http-config.d.ts +22 -0
- package/dist/proxy/smart-http-config.js +40 -0
- package/dist/proxy/smart-http-config.js.map +1 -0
- package/dist/reference/apply-actions.d.ts +9 -0
- package/dist/reference/apply-actions.js +84 -0
- package/dist/reference/apply-actions.js.map +1 -0
- package/dist/reference/branch-methods.d.ts +7 -0
- package/dist/reference/branch-methods.js +105 -0
- package/dist/reference/branch-methods.js.map +1 -0
- package/dist/reference/bytes.d.ts +22 -0
- package/dist/reference/bytes.js +62 -0
- package/dist/reference/bytes.js.map +1 -0
- package/dist/reference/clock.d.ts +2 -0
- package/dist/reference/clock.js +18 -0
- package/dist/reference/clock.js.map +1 -0
- package/dist/reference/commit-method.d.ts +5 -0
- package/dist/reference/commit-method.js +83 -0
- package/dist/reference/commit-method.js.map +1 -0
- package/dist/reference/file-map.d.ts +2 -0
- package/dist/reference/file-map.js +24 -0
- package/dist/reference/file-map.js.map +1 -0
- package/dist/reference/hash.d.ts +10 -0
- package/dist/reference/hash.js +25 -0
- package/dist/reference/hash.js.map +1 -0
- package/dist/reference/history.d.ts +2 -0
- package/dist/reference/history.js +65 -0
- package/dist/reference/history.js.map +1 -0
- package/dist/reference/lifecycle-methods.d.ts +9 -0
- package/dist/reference/lifecycle-methods.js +48 -0
- package/dist/reference/lifecycle-methods.js.map +1 -0
- package/dist/reference/read-methods.d.ts +13 -0
- package/dist/reference/read-methods.js +68 -0
- package/dist/reference/read-methods.js.map +1 -0
- package/dist/reference/reference-gateway.d.ts +18 -0
- package/dist/reference/reference-gateway.js +35 -0
- package/dist/reference/reference-gateway.js.map +1 -0
- package/dist/reference/repo-state.d.ts +43 -0
- package/dist/reference/repo-state.js +45 -0
- package/dist/reference/repo-state.js.map +1 -0
- package/dist/reference/run-method.d.ts +13 -0
- package/dist/reference/run-method.js +15 -0
- package/dist/reference/run-method.js.map +1 -0
- package/dist/reference/three-way-merge.d.ts +16 -0
- package/dist/reference/three-way-merge.js +45 -0
- package/dist/reference/three-way-merge.js.map +1 -0
- package/dist/reference/trailer.d.ts +7 -0
- package/dist/reference/trailer.js +16 -0
- package/dist/reference/trailer.js.map +1 -0
- package/dist/reference/tree-index.d.ts +2 -0
- package/dist/reference/tree-index.js +66 -0
- package/dist/reference/tree-index.js.map +1 -0
- package/dist/reference/write-commit.d.ts +15 -0
- package/dist/reference/write-commit.js +44 -0
- package/dist/reference/write-commit.js.map +1 -0
- package/dist/rpc/commit-exists.d.ts +16 -0
- package/dist/rpc/commit-exists.js +30 -0
- package/dist/rpc/commit-exists.js.map +1 -0
- package/dist/rpc/commit.d.ts +172 -0
- package/dist/rpc/commit.js +115 -0
- package/dist/rpc/commit.js.map +1 -0
- package/dist/rpc/list-tree.d.ts +59 -0
- package/dist/rpc/list-tree.js +54 -0
- package/dist/rpc/list-tree.js.map +1 -0
- package/dist/rpc/log.d.ts +35 -0
- package/dist/rpc/log.js +41 -0
- package/dist/rpc/log.js.map +1 -0
- package/dist/rpc/mint-read-token.d.ts +17 -0
- package/dist/rpc/mint-read-token.js +36 -0
- package/dist/rpc/mint-read-token.js.map +1 -0
- package/dist/rpc/promote.d.ts +39 -0
- package/dist/rpc/promote.js +69 -0
- package/dist/rpc/promote.js.map +1 -0
- package/dist/rpc/read-file.d.ts +44 -0
- package/dist/rpc/read-file.js +56 -0
- package/dist/rpc/read-file.js.map +1 -0
- package/dist/rpc/repo-lifecycle.d.ts +39 -0
- package/dist/rpc/repo-lifecycle.js +64 -0
- package/dist/rpc/repo-lifecycle.js.map +1 -0
- package/dist/rpc/resolve-ref.d.ts +15 -0
- package/dist/rpc/resolve-ref.js +28 -0
- package/dist/rpc/resolve-ref.js.map +1 -0
- package/dist/rpc/sync-branch.d.ts +107 -0
- package/dist/rpc/sync-branch.js +114 -0
- package/dist/rpc/sync-branch.js.map +1 -0
- package/dist/schemas/commit-action.d.ts +100 -0
- package/dist/schemas/commit-action.js +138 -0
- package/dist/schemas/commit-action.js.map +1 -0
- package/dist/schemas/commit.d.ts +2 -0
- package/dist/schemas/commit.js +24 -0
- package/dist/schemas/commit.js.map +1 -0
- package/dist/schemas/content-encoding.d.ts +24 -0
- package/dist/schemas/content-encoding.js +41 -0
- package/dist/schemas/content-encoding.js.map +1 -0
- package/dist/schemas/examples.d.ts +38 -0
- package/dist/schemas/examples.js +32 -0
- package/dist/schemas/examples.js.map +1 -0
- package/dist/schemas/gateway-config.d.ts +2 -0
- package/dist/schemas/gateway-config.js +72 -0
- package/dist/schemas/gateway-config.js.map +1 -0
- package/dist/schemas/gateway-error-body.d.ts +2 -0
- package/dist/schemas/gateway-error-body.js +188 -0
- package/dist/schemas/gateway-error-body.js.map +1 -0
- package/dist/schemas/identity.d.ts +21 -0
- package/dist/schemas/identity.js +40 -0
- package/dist/schemas/identity.js.map +1 -0
- package/dist/schemas/names.d.ts +26 -0
- package/dist/schemas/names.js +58 -0
- package/dist/schemas/names.js.map +1 -0
- package/dist/schemas/ref-update.d.ts +10 -0
- package/dist/schemas/ref-update.js +25 -0
- package/dist/schemas/ref-update.js.map +1 -0
- package/dist/schemas/sha.d.ts +8 -0
- package/dist/schemas/sha.js +14 -0
- package/dist/schemas/sha.js.map +1 -0
- package/dist/schemas/tree-entry.d.ts +2 -0
- package/dist/schemas/tree-entry.js +62 -0
- package/dist/schemas/tree-entry.js.map +1 -0
- package/dist/storage/git-remote.d.ts +17 -0
- package/dist/storage/git-remote.js +31 -0
- package/dist/storage/git-remote.js.map +1 -0
- package/dist/storage/storage-backend.d.ts +61 -0
- package/dist/storage/storage-backend.js +0 -0
- package/dist/storage/storage-errors.d.ts +12 -0
- package/dist/storage/storage-errors.js +22 -0
- package/dist/storage/storage-errors.js.map +1 -0
- package/dist/storage/storage-input.d.ts +7 -0
- package/dist/storage/storage-input.js +14 -0
- package/dist/storage/storage-input.js.map +1 -0
- package/dist/storage/storage-read.d.ts +13 -0
- package/dist/storage/storage-read.js +30 -0
- package/dist/storage/storage-read.js.map +1 -0
- package/dist/storage/storage-repo-info.d.ts +16 -0
- package/dist/storage/storage-repo-info.js +30 -0
- package/dist/storage/storage-repo-info.js.map +1 -0
- package/dist/storage/storage-tree-entry.d.ts +21 -0
- package/dist/storage/storage-tree-entry.js +17 -0
- package/dist/storage/storage-tree-entry.js.map +1 -0
- package/dist/tree-entry-BM_1gou1.d.ts +41 -0
- package/dist/tree-index-Bk721Phv.d.ts +14 -0
- package/package.json +401 -4
- package/src/behaviour/assertions.ts +75 -0
- package/src/behaviour/behaviour-case.ts +28 -0
- package/src/behaviour/behaviour-suite.ts +76 -0
- package/src/behaviour/commit-action-cases.ts +253 -0
- package/src/behaviour/commit-write-cases.ts +205 -0
- package/src/behaviour/fixtures.ts +103 -0
- package/src/behaviour/lifecycle-cases.ts +104 -0
- package/src/behaviour/promote-cases.ts +78 -0
- package/src/behaviour/read-cases.ts +176 -0
- package/src/behaviour/sync-cases.ts +156 -0
- package/src/gateway-error.ts +72 -0
- package/src/git-gateway.ts +76 -0
- package/src/health.ts +26 -0
- package/src/package-name.ts +4 -0
- package/src/proxy/audit-event.ts +135 -0
- package/src/proxy/branch-rule.ts +190 -0
- package/src/proxy/gateway-hooks.ts +67 -0
- package/src/proxy/git-operation.ts +36 -0
- package/src/proxy/policy-result.ts +127 -0
- package/src/proxy/principal.ts +81 -0
- package/src/proxy/push-policy-result.ts +86 -0
- package/src/proxy/push-policy.ts +158 -0
- package/src/proxy/request-credential.ts +47 -0
- package/src/proxy/smart-http-config.ts +158 -0
- package/src/reference/apply-actions.ts +96 -0
- package/src/reference/branch-methods.ts +105 -0
- package/src/reference/bytes.ts +66 -0
- package/src/reference/clock.ts +19 -0
- package/src/reference/commit-method.ts +97 -0
- package/src/reference/file-map.ts +35 -0
- package/src/reference/hash.ts +25 -0
- package/src/reference/history.ts +78 -0
- package/src/reference/lifecycle-methods.ts +52 -0
- package/src/reference/read-methods.ts +87 -0
- package/src/reference/reference-gateway.ts +50 -0
- package/src/reference/repo-state.ts +83 -0
- package/src/reference/run-method.ts +25 -0
- package/src/reference/three-way-merge.ts +42 -0
- package/src/reference/trailer.ts +18 -0
- package/src/reference/tree-index.ts +65 -0
- package/src/reference/write-commit.ts +44 -0
- package/src/rpc/commit-exists.ts +46 -0
- package/src/rpc/commit.ts +156 -0
- package/src/rpc/list-tree.ts +78 -0
- package/src/rpc/log.ts +51 -0
- package/src/rpc/mint-read-token.ts +59 -0
- package/src/rpc/promote.ts +72 -0
- package/src/rpc/read-file.ts +75 -0
- package/src/rpc/repo-lifecycle.ts +103 -0
- package/src/rpc/resolve-ref.ts +41 -0
- package/src/rpc/sync-branch.ts +149 -0
- package/src/schemas/commit-action.ts +157 -0
- package/src/schemas/commit.ts +43 -0
- package/src/schemas/content-encoding.ts +58 -0
- package/src/schemas/examples.ts +24 -0
- package/src/schemas/gateway-config.ts +116 -0
- package/src/schemas/gateway-error-body.ts +230 -0
- package/src/schemas/identity.ts +57 -0
- package/src/schemas/names.ts +126 -0
- package/src/schemas/ref-update.ts +38 -0
- package/src/schemas/sha.ts +20 -0
- package/src/schemas/tree-entry.ts +72 -0
- package/src/storage/git-remote.ts +58 -0
- package/src/storage/storage-backend.ts +65 -0
- package/src/storage/storage-errors.ts +24 -0
- package/src/storage/storage-input.ts +14 -0
- package/src/storage/storage-read.ts +45 -0
- package/src/storage/storage-repo-info.ts +46 -0
- package/src/storage/storage-tree-entry.ts +20 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { r as RpcInput, t as GitGateway } from "../git-gateway-VA9Tc5tn.js";
|
|
2
|
+
import { t as Commit } from "../commit-BEZmeAOl.js";
|
|
3
|
+
import { CommitActionInput } from "../schemas/commit-action.js";
|
|
4
|
+
/** The author behaviour cases commit as. */
|
|
5
|
+
export declare const AUTHOR: {
|
|
6
|
+
name: string;
|
|
7
|
+
email: string;
|
|
8
|
+
};
|
|
9
|
+
/** A fresh idempotency key, unique across runs. */
|
|
10
|
+
export declare function freshKey(label?: string): string;
|
|
11
|
+
/** Extra commit fields a case may set. */
|
|
12
|
+
export type CommitOptions = Partial<Omit<RpcInput<'commit'>, 'repo' | 'branch' | 'actions'>>;
|
|
13
|
+
/** Commits the actions to the branch, failing unless a new commit was written; returns it. */
|
|
14
|
+
export declare function commitActions(gateway: GitGateway, repo: string, branch: string, actions: CommitActionInput[], options?: CommitOptions): Promise<Commit>;
|
|
15
|
+
/** Upserts each file with text content (null deletes it) in one commit; returns the commit. */
|
|
16
|
+
export declare function writeFiles(gateway: GitGateway, repo: string, branch: string, files: Record<string, string | null>, options?: CommitOptions): Promise<Commit>;
|
|
17
|
+
/** Creates the repository with `main` holding the given text files; returns the first commit. */
|
|
18
|
+
export declare function seedRepo(gateway: GitGateway, repo: string, files?: Record<string, string>): Promise<Commit>;
|
|
19
|
+
/** Creates `branch` from `from` with one commit of the given files; returns that commit. */
|
|
20
|
+
export declare function branchFrom(gateway: GitGateway, repo: string, from: string, branch: string, files: Record<string, string | null>): Promise<Commit>;
|
|
21
|
+
/** The head of a branch, or null. */
|
|
22
|
+
export declare function headOf(gateway: GitGateway, repo: string, branch: string): Promise<string | null>;
|
|
23
|
+
/** The head of a branch, failing when it does not exist. */
|
|
24
|
+
export declare function requireHead(gateway: GitGateway, repo: string, branch: string): Promise<string>;
|
|
25
|
+
/** The text content of a file at a ref, or null when absent. */
|
|
26
|
+
export declare function readText(gateway: GitGateway, repo: string, ref: string, path: string): Promise<string | null>;
|
|
27
|
+
/** Every file path at a ref, sorted. */
|
|
28
|
+
export declare function filePaths(gateway: GitGateway, repo: string, ref: string): Promise<string[]>;
|
|
29
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { expectStatus, present } from "./assertions.js";
|
|
2
|
+
// src/behaviour/fixtures.ts
|
|
3
|
+
/** The author behaviour cases commit as. */
|
|
4
|
+
const AUTHOR = {
|
|
5
|
+
name: "Behaviour Suite",
|
|
6
|
+
email: "behaviour@example.com"
|
|
7
|
+
};
|
|
8
|
+
let keyCounter = 0;
|
|
9
|
+
/** A fresh idempotency key, unique across runs. */
|
|
10
|
+
function freshKey(label = "case") {
|
|
11
|
+
keyCounter += 1;
|
|
12
|
+
return `${label}-${keyCounter}-${crypto.randomUUID()}`;
|
|
13
|
+
}
|
|
14
|
+
/** Commits the actions to the branch, failing unless a new commit was written; returns it. */
|
|
15
|
+
async function commitActions(gateway, repo, branch, actions, options = {}) {
|
|
16
|
+
const output = await gateway.commit({
|
|
17
|
+
repo,
|
|
18
|
+
branch,
|
|
19
|
+
actions,
|
|
20
|
+
message: options.message ?? `Change ${branch}`,
|
|
21
|
+
author: options.author ?? AUTHOR,
|
|
22
|
+
idempotencyKey: options.idempotencyKey ?? freshKey(),
|
|
23
|
+
...options.committer === void 0 ? {} : { committer: options.committer },
|
|
24
|
+
...options.expectedHead === void 0 ? {} : { expectedHead: options.expectedHead },
|
|
25
|
+
...options.startBranch === void 0 ? {} : { startBranch: options.startBranch }
|
|
26
|
+
});
|
|
27
|
+
return expectStatus(output, "committed").commit;
|
|
28
|
+
}
|
|
29
|
+
/** Upserts each file with text content (null deletes it) in one commit; returns the commit. */
|
|
30
|
+
function writeFiles(gateway, repo, branch, files, options = {}) {
|
|
31
|
+
return commitActions(gateway, repo, branch, Object.entries(files).map(([path, content]) => content === null ? {
|
|
32
|
+
action: "delete",
|
|
33
|
+
path
|
|
34
|
+
} : {
|
|
35
|
+
action: "upsert",
|
|
36
|
+
path,
|
|
37
|
+
content
|
|
38
|
+
}), options);
|
|
39
|
+
}
|
|
40
|
+
/** Creates the repository with `main` holding the given text files; returns the first commit. */
|
|
41
|
+
async function seedRepo(gateway, repo, files = { "README.md": "# Seed\n" }) {
|
|
42
|
+
await gateway.createRepo({
|
|
43
|
+
repo,
|
|
44
|
+
defaultBranch: "main"
|
|
45
|
+
});
|
|
46
|
+
return writeFiles(gateway, repo, "main", files);
|
|
47
|
+
}
|
|
48
|
+
/** Creates `branch` from `from` with one commit of the given files; returns that commit. */
|
|
49
|
+
function branchFrom(gateway, repo, from, branch, files) {
|
|
50
|
+
return writeFiles(gateway, repo, branch, files, { startBranch: from });
|
|
51
|
+
}
|
|
52
|
+
/** The head of a branch, or null. */
|
|
53
|
+
async function headOf(gateway, repo, branch) {
|
|
54
|
+
return (await gateway.resolveRef({
|
|
55
|
+
repo,
|
|
56
|
+
ref: branch
|
|
57
|
+
}))?.sha ?? null;
|
|
58
|
+
}
|
|
59
|
+
/** The head of a branch, failing when it does not exist. */
|
|
60
|
+
async function requireHead(gateway, repo, branch) {
|
|
61
|
+
return present(await headOf(gateway, repo, branch), `branch ${branch} should exist`);
|
|
62
|
+
}
|
|
63
|
+
/** The text content of a file at a ref, or null when absent. */
|
|
64
|
+
async function readText(gateway, repo, ref, path) {
|
|
65
|
+
const file = await gateway.readFile({
|
|
66
|
+
repo,
|
|
67
|
+
ref,
|
|
68
|
+
path,
|
|
69
|
+
encoding: "text"
|
|
70
|
+
});
|
|
71
|
+
return file === null ? null : file.content;
|
|
72
|
+
}
|
|
73
|
+
/** Every file path at a ref, sorted. */
|
|
74
|
+
async function filePaths(gateway, repo, ref) {
|
|
75
|
+
return ((await gateway.listTree({
|
|
76
|
+
repo,
|
|
77
|
+
ref,
|
|
78
|
+
recursive: true
|
|
79
|
+
}))?.entries ?? []).filter((entry) => entry.type === "blob").map((entry) => entry.path);
|
|
80
|
+
}
|
|
81
|
+
export { AUTHOR, branchFrom, commitActions, filePaths, freshKey, headOf, readText, requireHead, seedRepo, writeFiles };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=fixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.js","names":[],"sources":["../../src/behaviour/fixtures.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { GitGateway, RpcInput } from '../git-gateway.ts';\nimport type { Commit } from '../schemas/commit.ts';\nimport type { CommitActionInput } from '../schemas/commit-action.ts';\nimport { expectStatus, present } from './assertions.ts';\n\n/** The author behaviour cases commit as. */\nexport const AUTHOR = { name: 'Behaviour Suite', email: 'behaviour@example.com' };\n\nlet keyCounter = 0;\n\n/** A fresh idempotency key, unique across runs. */\nexport function freshKey(label = 'case'): string {\n keyCounter += 1;\n return `${label}-${keyCounter}-${crypto.randomUUID()}`;\n}\n\n/** Extra commit fields a case may set. */\nexport type CommitOptions = Partial<Omit<RpcInput<'commit'>, 'repo' | 'branch' | 'actions'>>;\n\n/** Commits the actions to the branch, failing unless a new commit was written; returns it. */\nexport async function commitActions(\n gateway: GitGateway,\n repo: string,\n branch: string,\n actions: CommitActionInput[],\n options: CommitOptions = {},\n): Promise<Commit> {\n const output = await gateway.commit({\n repo,\n branch,\n actions,\n message: options.message ?? `Change ${branch}`,\n author: options.author ?? AUTHOR,\n idempotencyKey: options.idempotencyKey ?? freshKey(),\n ...(options.committer === undefined ? {} : { committer: options.committer }),\n ...(options.expectedHead === undefined ? {} : { expectedHead: options.expectedHead }),\n ...(options.startBranch === undefined ? {} : { startBranch: options.startBranch }),\n });\n return expectStatus(output, 'committed').commit;\n}\n\n/** Upserts each file with text content (null deletes it) in one commit; returns the commit. */\nexport function writeFiles(\n gateway: GitGateway,\n repo: string,\n branch: string,\n files: Record<string, string | null>,\n options: CommitOptions = {},\n): Promise<Commit> {\n const actions: CommitActionInput[] = Object.entries(files).map(([path, content]) =>\n content === null ? { action: 'delete', path } : { action: 'upsert', path, content },\n );\n return commitActions(gateway, repo, branch, actions, options);\n}\n\n/** Creates the repository with `main` holding the given text files; returns the first commit. */\nexport async function seedRepo(\n gateway: GitGateway,\n repo: string,\n files: Record<string, string> = { 'README.md': '# Seed\\n' },\n): Promise<Commit> {\n await gateway.createRepo({ repo, defaultBranch: 'main' });\n return writeFiles(gateway, repo, 'main', files);\n}\n\n/** Creates `branch` from `from` with one commit of the given files; returns that commit. */\nexport function branchFrom(\n gateway: GitGateway,\n repo: string,\n from: string,\n branch: string,\n files: Record<string, string | null>,\n): Promise<Commit> {\n return writeFiles(gateway, repo, branch, files, { startBranch: from });\n}\n\n/** The head of a branch, or null. */\nexport async function headOf(gateway: GitGateway, repo: string, branch: string): Promise<string | null> {\n return (await gateway.resolveRef({ repo, ref: branch }))?.sha ?? null;\n}\n\n/** The head of a branch, failing when it does not exist. */\nexport async function requireHead(gateway: GitGateway, repo: string, branch: string): Promise<string> {\n return present(await headOf(gateway, repo, branch), `branch ${branch} should exist`);\n}\n\n/** The text content of a file at a ref, or null when absent. */\nexport async function readText(\n gateway: GitGateway,\n repo: string,\n ref: string,\n path: string,\n): Promise<string | null> {\n const file = await gateway.readFile({ repo, ref, path, encoding: 'text' });\n return file === null ? null : file.content;\n}\n\n/** Every file path at a ref, sorted. */\nexport async function filePaths(gateway: GitGateway, repo: string, ref: string): Promise<string[]> {\n const listing = await gateway.listTree({ repo, ref, recursive: true });\n return (listing?.entries ?? []).filter((entry) => entry.type === 'blob').map((entry) => entry.path);\n}\n"],"mappings":";;;AAOA,MAAa,SAAS;CAAE,MAAM;CAAmB,OAAO;AAAwB;AAEhF,IAAI,aAAa;;AAGjB,SAAgB,SAAS,QAAQ,QAAgB;CAC/C,cAAc;CACd,OAAO,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,WAAW;AACrD;;AAMA,eAAsB,cACpB,SACA,MACA,QACA,SACA,UAAyB,CAAC,GACT;CACjB,MAAM,SAAS,MAAM,QAAQ,OAAO;EAClC;EACA;EACA;EACA,SAAS,QAAQ,WAAW,UAAU;EACtC,QAAQ,QAAQ,UAAU;EAC1B,gBAAgB,QAAQ,kBAAkB,SAAS;EACnD,GAAI,QAAQ,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW,QAAQ,UAAU;EAC1E,GAAI,QAAQ,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,cAAc,QAAQ,aAAa;EACnF,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAClF,CAAC;CACD,OAAO,aAAa,QAAQ,WAAW,CAAC,CAAC;AAC3C;;AAGA,SAAgB,WACd,SACA,MACA,QACA,OACA,UAAyB,CAAC,GACT;CAIjB,OAAO,cAAc,SAAS,MAAM,QAHC,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,aACrE,YAAY,OAAO;EAAE,QAAQ;EAAU;CAAK,IAAI;EAAE,QAAQ;EAAU;EAAM;CAAQ,CAElC,GAAG,OAAO;AAC9D;;AAGA,eAAsB,SACpB,SACA,MACA,QAAgC,EAAE,aAAa,WAAW,GACzC;CACjB,MAAM,QAAQ,WAAW;EAAE;EAAM,eAAe;CAAO,CAAC;CACxD,OAAO,WAAW,SAAS,MAAM,QAAQ,KAAK;AAChD;;AAGA,SAAgB,WACd,SACA,MACA,MACA,QACA,OACiB;CACjB,OAAO,WAAW,SAAS,MAAM,QAAQ,OAAO,EAAE,aAAa,KAAK,CAAC;AACvE;;AAGA,eAAsB,OAAO,SAAqB,MAAc,QAAwC;CACtG,QAAQ,MAAM,QAAQ,WAAW;EAAE;EAAM,KAAK;CAAO,CAAC,EAAA,EAAI,OAAO;AACnE;;AAGA,eAAsB,YAAY,SAAqB,MAAc,QAAiC;CACpG,OAAO,QAAQ,MAAM,OAAO,SAAS,MAAM,MAAM,GAAG,UAAU,OAAO,cAAc;AACrF;;AAGA,eAAsB,SACpB,SACA,MACA,KACA,MACwB;CACxB,MAAM,OAAO,MAAM,QAAQ,SAAS;EAAE;EAAM;EAAK;EAAM,UAAU;CAAO,CAAC;CACzE,OAAO,SAAS,OAAO,OAAO,KAAK;AACrC;;AAGA,eAAsB,UAAU,SAAqB,MAAc,KAAgC;CAEjG,SAAQ,MADc,QAAQ,SAAS;EAAE;EAAM;EAAK,WAAW;CAAK,CAAC,EAAA,EACpD,WAAW,CAAC,EAAA,CAAG,QAAQ,UAAU,MAAM,SAAS,MAAM,CAAC,CAAC,KAAK,UAAU,MAAM,IAAI;AACpG"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { assertEqual, assertTrue, expectGatewayError } from "./assertions.js";
|
|
2
|
+
import { behaviourCase } from "./behaviour-case.js";
|
|
3
|
+
import { AUTHOR, freshKey, headOf, seedRepo } from "./fixtures.js";
|
|
4
|
+
// src/behaviour/lifecycle-cases.ts
|
|
5
|
+
const GROUP = "repositories";
|
|
6
|
+
const SHA = "ffffffffffffffffffffffffffffffffffffffff";
|
|
7
|
+
/** createRepo, deleteRepo, mintReadToken, missing repositories and input validation. */
|
|
8
|
+
const lifecycleCases = [
|
|
9
|
+
behaviourCase(GROUP, "createRepo creates an empty repository", async ({ gateway, repo }) => {
|
|
10
|
+
const info = await gateway.createRepo({ repo });
|
|
11
|
+
assertEqual([info.name, info.defaultBranch], [repo, "main"], "name and default branch");
|
|
12
|
+
assertTrue(info.remoteUrl.endsWith(`/${repo}.git`), "remote URL ends in /<repo>.git");
|
|
13
|
+
assertEqual(await headOf(gateway, repo, "main"), null, "no branches until the first commit");
|
|
14
|
+
}),
|
|
15
|
+
behaviourCase(GROUP, "createRepo honours defaultBranch", async ({ gateway, repo }) => {
|
|
16
|
+
assertEqual((await gateway.createRepo({
|
|
17
|
+
repo,
|
|
18
|
+
defaultBranch: "trunk"
|
|
19
|
+
})).defaultBranch, "trunk", "default");
|
|
20
|
+
}),
|
|
21
|
+
behaviourCase(GROUP, "createRepo of an existing name is repo_exists", async ({ gateway, repo }) => {
|
|
22
|
+
await seedRepo(gateway, repo);
|
|
23
|
+
const error = await expectGatewayError(gateway.createRepo({ repo }), "repo_exists");
|
|
24
|
+
assertEqual(error.details.repo, repo, "names the repository");
|
|
25
|
+
assertTrue(await headOf(gateway, repo, "main") !== null, "existing repository untouched");
|
|
26
|
+
}),
|
|
27
|
+
behaviourCase(GROUP, "deleteRepo deletes, and deleting again reports false", async ({ gateway, repo }) => {
|
|
28
|
+
await seedRepo(gateway, repo);
|
|
29
|
+
assertEqual(await gateway.deleteRepo({ repo }), { deleted: true }, "deleted");
|
|
30
|
+
assertEqual(await gateway.deleteRepo({ repo }), { deleted: false }, "already gone");
|
|
31
|
+
await expectGatewayError(gateway.resolveRef({
|
|
32
|
+
repo,
|
|
33
|
+
ref: "main"
|
|
34
|
+
}), "repo_not_found");
|
|
35
|
+
}),
|
|
36
|
+
behaviourCase(GROUP, "every call on a missing repository is repo_not_found", async ({ gateway, repo }) => {
|
|
37
|
+
const calls = [
|
|
38
|
+
() => gateway.commit({
|
|
39
|
+
repo,
|
|
40
|
+
branch: "main",
|
|
41
|
+
message: "m",
|
|
42
|
+
author: AUTHOR,
|
|
43
|
+
idempotencyKey: freshKey(),
|
|
44
|
+
actions: [{
|
|
45
|
+
action: "create",
|
|
46
|
+
path: "a",
|
|
47
|
+
content: "a"
|
|
48
|
+
}]
|
|
49
|
+
}),
|
|
50
|
+
() => gateway.readFile({
|
|
51
|
+
repo,
|
|
52
|
+
ref: "main",
|
|
53
|
+
path: "a"
|
|
54
|
+
}),
|
|
55
|
+
() => gateway.listTree({
|
|
56
|
+
repo,
|
|
57
|
+
ref: "main"
|
|
58
|
+
}),
|
|
59
|
+
() => gateway.resolveRef({
|
|
60
|
+
repo,
|
|
61
|
+
ref: "main"
|
|
62
|
+
}),
|
|
63
|
+
() => gateway.log({
|
|
64
|
+
repo,
|
|
65
|
+
ref: "main"
|
|
66
|
+
}),
|
|
67
|
+
() => gateway.commitExists({
|
|
68
|
+
repo,
|
|
69
|
+
sha: SHA
|
|
70
|
+
}),
|
|
71
|
+
() => gateway.syncBranch({
|
|
72
|
+
repo,
|
|
73
|
+
from: "main",
|
|
74
|
+
into: "staging"
|
|
75
|
+
}),
|
|
76
|
+
() => gateway.promote({
|
|
77
|
+
repo,
|
|
78
|
+
from: "staging",
|
|
79
|
+
into: "main",
|
|
80
|
+
sha: SHA
|
|
81
|
+
}),
|
|
82
|
+
() => gateway.mintReadToken({ repo })
|
|
83
|
+
];
|
|
84
|
+
for (const call of calls) assertEqual((await expectGatewayError(call(), "repo_not_found")).details.repo, repo, "names the repository");
|
|
85
|
+
}),
|
|
86
|
+
behaviourCase(GROUP, "mintReadToken returns a token, expiry and clone URL", async ({ gateway, repo }) => {
|
|
87
|
+
await seedRepo(gateway, repo);
|
|
88
|
+
const short = await gateway.mintReadToken({
|
|
89
|
+
repo,
|
|
90
|
+
ttlSeconds: 60
|
|
91
|
+
});
|
|
92
|
+
const long = await gateway.mintReadToken({
|
|
93
|
+
repo,
|
|
94
|
+
ttlSeconds: 86400
|
|
95
|
+
});
|
|
96
|
+
assertTrue(short.token.length >= 16, "token is long enough to be a secret");
|
|
97
|
+
assertTrue(short.remoteUrl.endsWith(`/${repo}.git`), "clone URL");
|
|
98
|
+
assertTrue(Date.parse(long.expiresAt) - Date.parse(short.expiresAt) > 8e7, "ttl honoured");
|
|
99
|
+
}),
|
|
100
|
+
behaviourCase(GROUP, "malformed input is invalid_input and changes nothing", async ({ gateway, repo }) => {
|
|
101
|
+
const seed = await seedRepo(gateway, repo);
|
|
102
|
+
const bad = [
|
|
103
|
+
() => gateway.createRepo({ repo: "bad/name" }),
|
|
104
|
+
() => gateway.readFile({
|
|
105
|
+
repo,
|
|
106
|
+
ref: "main",
|
|
107
|
+
path: "../escape"
|
|
108
|
+
}),
|
|
109
|
+
() => gateway.readFile({
|
|
110
|
+
repo,
|
|
111
|
+
ref: "main",
|
|
112
|
+
path: ".git/config"
|
|
113
|
+
}),
|
|
114
|
+
() => gateway.resolveRef({
|
|
115
|
+
repo,
|
|
116
|
+
ref: "a..b"
|
|
117
|
+
}),
|
|
118
|
+
() => gateway.commitExists({
|
|
119
|
+
repo,
|
|
120
|
+
sha: "ABC"
|
|
121
|
+
}),
|
|
122
|
+
() => gateway.log({
|
|
123
|
+
repo,
|
|
124
|
+
ref: "main",
|
|
125
|
+
limit: 0
|
|
126
|
+
}),
|
|
127
|
+
() => gateway.mintReadToken({
|
|
128
|
+
repo,
|
|
129
|
+
ttlSeconds: 5
|
|
130
|
+
}),
|
|
131
|
+
() => gateway.commit({
|
|
132
|
+
repo,
|
|
133
|
+
branch: "main",
|
|
134
|
+
message: "m",
|
|
135
|
+
author: AUTHOR,
|
|
136
|
+
idempotencyKey: freshKey(),
|
|
137
|
+
actions: []
|
|
138
|
+
}),
|
|
139
|
+
() => gateway.commit({
|
|
140
|
+
repo,
|
|
141
|
+
branch: "main",
|
|
142
|
+
message: "m",
|
|
143
|
+
author: AUTHOR,
|
|
144
|
+
idempotencyKey: freshKey(),
|
|
145
|
+
actions: [{
|
|
146
|
+
action: "move",
|
|
147
|
+
path: "README.md",
|
|
148
|
+
previousPath: "README.md"
|
|
149
|
+
}]
|
|
150
|
+
})
|
|
151
|
+
];
|
|
152
|
+
for (const call of bad) await expectGatewayError(call(), "invalid_input");
|
|
153
|
+
assertEqual(await headOf(gateway, repo, "main"), seed.sha, "nothing written");
|
|
154
|
+
})
|
|
155
|
+
];
|
|
156
|
+
export { lifecycleCases };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=lifecycle-cases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-cases.js","names":[],"sources":["../../src/behaviour/lifecycle-cases.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { assertEqual, assertTrue, expectGatewayError } from './assertions.ts';\nimport { behaviourCase, type BehaviourCase } from './behaviour-case.ts';\nimport { AUTHOR, freshKey, headOf, seedRepo } from './fixtures.ts';\n\nconst GROUP = 'repositories';\nconst SHA = 'ffffffffffffffffffffffffffffffffffffffff';\n\n/** createRepo, deleteRepo, mintReadToken, missing repositories and input validation. */\nexport const lifecycleCases: readonly BehaviourCase[] = [\n behaviourCase(GROUP, 'createRepo creates an empty repository', async ({ gateway, repo }) => {\n const info = await gateway.createRepo({ repo });\n assertEqual([info.name, info.defaultBranch], [repo, 'main'], 'name and default branch');\n assertTrue(info.remoteUrl.endsWith(`/${repo}.git`), 'remote URL ends in /<repo>.git');\n assertEqual(await headOf(gateway, repo, 'main'), null, 'no branches until the first commit');\n }),\n behaviourCase(GROUP, 'createRepo honours defaultBranch', async ({ gateway, repo }) => {\n assertEqual(\n (await gateway.createRepo({ repo, defaultBranch: 'trunk' })).defaultBranch,\n 'trunk',\n 'default',\n );\n }),\n behaviourCase(GROUP, 'createRepo of an existing name is repo_exists', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const error = await expectGatewayError(gateway.createRepo({ repo }), 'repo_exists');\n assertEqual(error.details.repo, repo, 'names the repository');\n assertTrue((await headOf(gateway, repo, 'main')) !== null, 'existing repository untouched');\n }),\n behaviourCase(GROUP, 'deleteRepo deletes, and deleting again reports false', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n assertEqual(await gateway.deleteRepo({ repo }), { deleted: true }, 'deleted');\n assertEqual(await gateway.deleteRepo({ repo }), { deleted: false }, 'already gone');\n await expectGatewayError(gateway.resolveRef({ repo, ref: 'main' }), 'repo_not_found');\n }),\n behaviourCase(GROUP, 'every call on a missing repository is repo_not_found', async ({ gateway, repo }) => {\n const calls: (() => Promise<unknown>)[] = [\n () =>\n gateway.commit({\n repo,\n branch: 'main',\n message: 'm',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions: [{ action: 'create', path: 'a', content: 'a' }],\n }),\n () => gateway.readFile({ repo, ref: 'main', path: 'a' }),\n () => gateway.listTree({ repo, ref: 'main' }),\n () => gateway.resolveRef({ repo, ref: 'main' }),\n () => gateway.log({ repo, ref: 'main' }),\n () => gateway.commitExists({ repo, sha: SHA }),\n () => gateway.syncBranch({ repo, from: 'main', into: 'staging' }),\n () => gateway.promote({ repo, from: 'staging', into: 'main', sha: SHA }),\n () => gateway.mintReadToken({ repo }),\n ];\n for (const call of calls) {\n assertEqual(\n (await expectGatewayError(call(), 'repo_not_found')).details.repo,\n repo,\n 'names the repository',\n );\n }\n }),\n behaviourCase(GROUP, 'mintReadToken returns a token, expiry and clone URL', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const short = await gateway.mintReadToken({ repo, ttlSeconds: 60 });\n const long = await gateway.mintReadToken({ repo, ttlSeconds: 86_400 });\n assertTrue(short.token.length >= 16, 'token is long enough to be a secret');\n assertTrue(short.remoteUrl.endsWith(`/${repo}.git`), 'clone URL');\n assertTrue(Date.parse(long.expiresAt) - Date.parse(short.expiresAt) > 80_000_000, 'ttl honoured');\n }),\n behaviourCase(GROUP, 'malformed input is invalid_input and changes nothing', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const bad: (() => Promise<unknown>)[] = [\n () => gateway.createRepo({ repo: 'bad/name' }),\n () => gateway.readFile({ repo, ref: 'main', path: '../escape' }),\n () => gateway.readFile({ repo, ref: 'main', path: '.git/config' }),\n () => gateway.resolveRef({ repo, ref: 'a..b' }),\n () => gateway.commitExists({ repo, sha: 'ABC' }),\n () => gateway.log({ repo, ref: 'main', limit: 0 }),\n () => gateway.mintReadToken({ repo, ttlSeconds: 5 }),\n () =>\n gateway.commit({\n repo,\n branch: 'main',\n message: 'm',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions: [],\n }),\n () =>\n gateway.commit({\n repo,\n branch: 'main',\n message: 'm',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions: [{ action: 'move', path: 'README.md', previousPath: 'README.md' }],\n }),\n ];\n for (const call of bad) await expectGatewayError(call(), 'invalid_input');\n assertEqual(await headOf(gateway, repo, 'main'), seed.sha, 'nothing written');\n }),\n];\n"],"mappings":";;;;AAKA,MAAM,QAAQ;AACd,MAAM,MAAM;;AAGZ,MAAa,iBAA2C;CACtD,cAAc,OAAO,0CAA0C,OAAO,EAAE,SAAS,WAAW;EAC1F,MAAM,OAAO,MAAM,QAAQ,WAAW,EAAE,KAAK,CAAC;EAC9C,YAAY,CAAC,KAAK,MAAM,KAAK,aAAa,GAAG,CAAC,MAAM,MAAM,GAAG,yBAAyB;EACtF,WAAW,KAAK,UAAU,SAAS,IAAI,KAAK,KAAK,GAAG,gCAAgC;EACpF,YAAY,MAAM,OAAO,SAAS,MAAM,MAAM,GAAG,MAAM,oCAAoC;CAC7F,CAAC;CACD,cAAc,OAAO,oCAAoC,OAAO,EAAE,SAAS,WAAW;EACpF,aACG,MAAM,QAAQ,WAAW;GAAE;GAAM,eAAe;EAAQ,CAAC,EAAA,CAAG,eAC7D,SACA,S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;IACb;IACA,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,gBAAgB,SAAS;IACzB,SAAS,CAAC;KAAE,QAAQ;KAAQ,MAAM;KAAa,cAAc;IAAY,CAAC;GAC5E,CAAC;EACL;EACA,KAAK,MAAM,QAAQ,KAAK,MAAM,mBAAmB,KAAK,GAAG,eAAe;EACxE,YAAY,MAAM,OAAO,SAAS,MAAM,MAAM,GAAG,KAAK,KAAK,iBAAiB;CAC9E,CAAC;AACH"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ZERO_SHA } from "../schemas/sha.js";
|
|
2
|
+
import { assertEqual, expectGatewayError } from "./assertions.js";
|
|
3
|
+
import { behaviourCase } from "./behaviour-case.js";
|
|
4
|
+
import { branchFrom, requireHead, seedRepo, writeFiles } from "./fixtures.js";
|
|
5
|
+
// src/behaviour/promote-cases.ts
|
|
6
|
+
const GROUP = "promote";
|
|
7
|
+
/** promote fast-forwards from the source head only, and every refusal. */
|
|
8
|
+
const promoteCases = [
|
|
9
|
+
behaviourCase(GROUP, "promotes the source head when it contains the target head", async ({ gateway, repo }) => {
|
|
10
|
+
const seed = await seedRepo(gateway, repo);
|
|
11
|
+
const staging = await branchFrom(gateway, repo, "main", "staging", { "new.md": "n" });
|
|
12
|
+
const output = await gateway.promote({
|
|
13
|
+
repo,
|
|
14
|
+
from: "staging",
|
|
15
|
+
into: "main",
|
|
16
|
+
sha: staging.sha
|
|
17
|
+
});
|
|
18
|
+
assertEqual(output, {
|
|
19
|
+
status: "promoted",
|
|
20
|
+
refUpdate: {
|
|
21
|
+
ref: "refs/heads/main",
|
|
22
|
+
oldSha: seed.sha,
|
|
23
|
+
newSha: staging.sha
|
|
24
|
+
}
|
|
25
|
+
}, "fast-forwarded");
|
|
26
|
+
assertEqual(await requireHead(gateway, repo, "main"), staging.sha, "main moved");
|
|
27
|
+
}),
|
|
28
|
+
behaviourCase(GROUP, "up_to_date when the target already points at sha", async ({ gateway, repo }) => {
|
|
29
|
+
const seed = await seedRepo(gateway, repo);
|
|
30
|
+
await gateway.promote({
|
|
31
|
+
repo,
|
|
32
|
+
from: "main",
|
|
33
|
+
into: "production",
|
|
34
|
+
sha: seed.sha
|
|
35
|
+
});
|
|
36
|
+
const output = await gateway.promote({
|
|
37
|
+
repo,
|
|
38
|
+
from: "main",
|
|
39
|
+
into: "production",
|
|
40
|
+
sha: seed.sha
|
|
41
|
+
});
|
|
42
|
+
assertEqual(output, {
|
|
43
|
+
status: "up_to_date",
|
|
44
|
+
head: seed.sha
|
|
45
|
+
}, "nothing to do");
|
|
46
|
+
}),
|
|
47
|
+
behaviourCase(GROUP, "a missing target branch is created at sha", async ({ gateway, repo }) => {
|
|
48
|
+
const seed = await seedRepo(gateway, repo);
|
|
49
|
+
const output = await gateway.promote({
|
|
50
|
+
repo,
|
|
51
|
+
from: "main",
|
|
52
|
+
into: "production",
|
|
53
|
+
sha: seed.sha
|
|
54
|
+
});
|
|
55
|
+
assertEqual(output, {
|
|
56
|
+
status: "promoted",
|
|
57
|
+
refUpdate: {
|
|
58
|
+
ref: "refs/heads/production",
|
|
59
|
+
oldSha: ZERO_SHA,
|
|
60
|
+
newSha: seed.sha
|
|
61
|
+
}
|
|
62
|
+
}, "created");
|
|
63
|
+
}),
|
|
64
|
+
behaviourCase(GROUP, "refuses a sha that is not the source head", async ({ gateway, repo }) => {
|
|
65
|
+
const seed = await seedRepo(gateway, repo);
|
|
66
|
+
const staging = await branchFrom(gateway, repo, "main", "staging", { "a.md": "a" });
|
|
67
|
+
const newer = await writeFiles(gateway, repo, "staging", { "b.md": "b" });
|
|
68
|
+
const error = await expectGatewayError(gateway.promote({
|
|
69
|
+
repo,
|
|
70
|
+
from: "staging",
|
|
71
|
+
into: "main",
|
|
72
|
+
sha: staging.sha
|
|
73
|
+
}), "not_head_of_source");
|
|
74
|
+
assertEqual(error.details, {
|
|
75
|
+
from: "staging",
|
|
76
|
+
sha: staging.sha,
|
|
77
|
+
head: newer.sha
|
|
78
|
+
}, "details");
|
|
79
|
+
assertEqual(await requireHead(gateway, repo, "main"), seed.sha, "main unchanged");
|
|
80
|
+
}),
|
|
81
|
+
behaviourCase(GROUP, "refuses an unknown sha as not_head_of_source", async ({ gateway, repo }) => {
|
|
82
|
+
await seedRepo(gateway, repo);
|
|
83
|
+
await branchFrom(gateway, repo, "main", "staging", { "a.md": "a" });
|
|
84
|
+
await expectGatewayError(gateway.promote({
|
|
85
|
+
repo,
|
|
86
|
+
from: "staging",
|
|
87
|
+
into: "main",
|
|
88
|
+
sha: "ffffffffffffffffffffffffffffffffffffffff"
|
|
89
|
+
}), "not_head_of_source");
|
|
90
|
+
}),
|
|
91
|
+
behaviourCase(GROUP, "refuses a non-fast-forward and never merges", async ({ gateway, repo }) => {
|
|
92
|
+
await seedRepo(gateway, repo);
|
|
93
|
+
const staging = await branchFrom(gateway, repo, "main", "staging", { "a.md": "a" });
|
|
94
|
+
const hotfix = await writeFiles(gateway, repo, "main", { "hotfix.md": "h" });
|
|
95
|
+
const error = await expectGatewayError(gateway.promote({
|
|
96
|
+
repo,
|
|
97
|
+
from: "staging",
|
|
98
|
+
into: "main",
|
|
99
|
+
sha: staging.sha
|
|
100
|
+
}), "not_fast_forward");
|
|
101
|
+
assertEqual(error.details, {
|
|
102
|
+
into: "main",
|
|
103
|
+
sha: staging.sha,
|
|
104
|
+
head: hotfix.sha
|
|
105
|
+
}, "details");
|
|
106
|
+
assertEqual(await requireHead(gateway, repo, "main"), hotfix.sha, "main unchanged");
|
|
107
|
+
assertEqual(await requireHead(gateway, repo, "staging"), staging.sha, "staging unchanged");
|
|
108
|
+
}),
|
|
109
|
+
behaviourCase(GROUP, "a missing source branch is ref_not_found", async ({ gateway, repo }) => {
|
|
110
|
+
const seed = await seedRepo(gateway, repo);
|
|
111
|
+
const call = gateway.promote({
|
|
112
|
+
repo,
|
|
113
|
+
from: "staging",
|
|
114
|
+
into: "main",
|
|
115
|
+
sha: seed.sha
|
|
116
|
+
});
|
|
117
|
+
assertEqual((await expectGatewayError(call, "ref_not_found")).details.ref, "staging", "names the source");
|
|
118
|
+
})
|
|
119
|
+
];
|
|
120
|
+
export { promoteCases };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=promote-cases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote-cases.js","names":[],"sources":["../../src/behaviour/promote-cases.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { ZERO_SHA } from '../schemas/sha.ts';\nimport { assertEqual, expectGatewayError } from './assertions.ts';\nimport { behaviourCase, type BehaviourCase } from './behaviour-case.ts';\nimport { branchFrom, requireHead, seedRepo, writeFiles } from './fixtures.ts';\n\nconst GROUP = 'promote';\n\n/** promote fast-forwards from the source head only, and every refusal. */\nexport const promoteCases: readonly BehaviourCase[] = [\n behaviourCase(\n GROUP,\n 'promotes the source head when it contains the target head',\n async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'new.md': 'n' });\n const output = await gateway.promote({ repo, from: 'staging', into: 'main', sha: staging.sha });\n assertEqual(\n output,\n { status: 'promoted', refUpdate: { ref: 'refs/heads/main', oldSha: seed.sha, newSha: staging.sha } },\n 'fast-forwarded',\n );\n assertEqual(await requireHead(gateway, repo, 'main'), staging.sha, 'main moved');\n },\n ),\n behaviourCase(GROUP, 'up_to_date when the target already points at sha', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n await gateway.promote({ repo, from: 'main', into: 'production', sha: seed.sha });\n const output = await gateway.promote({ repo, from: 'main', into: 'production', sha: seed.sha });\n assertEqual(output, { status: 'up_to_date', head: seed.sha }, 'nothing to do');\n }),\n behaviourCase(GROUP, 'a missing target branch is created at sha', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const output = await gateway.promote({ repo, from: 'main', into: 'production', sha: seed.sha });\n assertEqual(\n output,\n { status: 'promoted', refUpdate: { ref: 'refs/heads/production', oldSha: ZERO_SHA, newSha: seed.sha } },\n 'created',\n );\n }),\n behaviourCase(GROUP, 'refuses a sha that is not the source head', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'a.md': 'a' });\n const newer = await writeFiles(gateway, repo, 'staging', { 'b.md': 'b' });\n const error = await expectGatewayError(\n gateway.promote({ repo, from: 'staging', into: 'main', sha: staging.sha }),\n 'not_head_of_source',\n );\n assertEqual(error.details, { from: 'staging', sha: staging.sha, head: newer.sha }, 'details');\n assertEqual(await requireHead(gateway, repo, 'main'), seed.sha, 'main unchanged');\n }),\n behaviourCase(GROUP, 'refuses an unknown sha as not_head_of_source', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n await branchFrom(gateway, repo, 'main', 'staging', { 'a.md': 'a' });\n const sha = 'ffffffffffffffffffffffffffffffffffffffff';\n await expectGatewayError(\n gateway.promote({ repo, from: 'staging', into: 'main', sha }),\n 'not_head_of_source',\n );\n }),\n behaviourCase(GROUP, 'refuses a non-fast-forward and never merges', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'a.md': 'a' });\n const hotfix = await writeFiles(gateway, repo, 'main', { 'hotfix.md': 'h' });\n const error = await expectGatewayError(\n gateway.promote({ repo, from: 'staging', into: 'main', sha: staging.sha }),\n 'not_fast_forward',\n );\n assertEqual(error.details, { into: 'main', sha: staging.sha, head: hotfix.sha }, 'details');\n assertEqual(await requireHead(gateway, repo, 'main'), hotfix.sha, 'main unchanged');\n assertEqual(await requireHead(gateway, repo, 'staging'), staging.sha, 'staging unchanged');\n }),\n behaviourCase(GROUP, 'a missing source branch is ref_not_found', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const call = gateway.promote({ repo, from: 'staging', into: 'main', sha: seed.sha });\n assertEqual((await expectGatewayError(call, 'ref_not_found')).details.ref, 'staging', 'names the source');\n }),\n];\n"],"mappings":";;;;;AAMA,MA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