@halonicjs/testing 0.1.0 → 0.1.1

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.
Files changed (153) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  4. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  5. package/dist/adapters/http-kit/src/index.d.ts +1 -0
  6. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  7. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  8. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  9. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  10. package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
  11. package/dist/adapters/integration-kit/src/declaration.js +4 -3
  12. package/dist/adapters/integration-kit/src/host.d.ts +7 -1
  13. package/dist/adapters/integration-kit/src/host.js +1 -0
  14. package/dist/adapters/integration-kit/src/index.d.ts +3 -1
  15. package/dist/adapters/integration-kit/src/index.js +1 -0
  16. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
  17. package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
  18. package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
  19. package/dist/adapters/integration-kit/src/limited-http.js +53 -10
  20. package/dist/adapters/integration-kit/src/loader.d.ts +29 -2
  21. package/dist/adapters/integration-kit/src/loader.js +44 -12
  22. package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
  23. package/dist/adapters/integration-kit/src/own-request.js +1 -1
  24. package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
  25. package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
  26. package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
  27. package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
  28. package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
  29. package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
  30. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
  31. package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
  32. package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
  33. package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
  34. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  35. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  36. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  37. package/dist/core/events/src/blocked-sites.js +89 -0
  38. package/dist/core/events/src/index.d.ts +5 -1
  39. package/dist/core/events/src/index.js +3 -0
  40. package/dist/core/events/src/run-basics.d.ts +30 -7
  41. package/dist/core/events/src/run-event.d.ts +49 -5
  42. package/dist/core/events/src/run-reads.d.ts +25 -0
  43. package/dist/core/events/src/run-reads.js +44 -0
  44. package/dist/core/events/src/run-sends.d.ts +47 -0
  45. package/dist/core/events/src/run-sends.js +68 -0
  46. package/dist/core/events/src/summarize.js +5 -1
  47. package/dist/core/events/src/timeline-entry.js +1 -0
  48. package/dist/core/format/src/index.d.ts +7 -5
  49. package/dist/core/format/src/index.js +5 -3
  50. package/dist/core/format/src/integration/index.d.ts +3 -2
  51. package/dist/core/format/src/integration/index.js +2 -1
  52. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
  53. package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
  54. package/dist/core/format/src/kinds/agent/schema.js +2 -2
  55. package/dist/core/format/src/kinds/connector/is-local.js +1 -1
  56. package/dist/core/format/src/kinds/connector/kind.js +99 -0
  57. package/dist/core/format/src/kinds/connector/schema.d.ts +24 -0
  58. package/dist/core/format/src/kinds/connector/schema.js +53 -2
  59. package/dist/core/format/src/kinds/deployments/kind.js +25 -1
  60. package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
  61. package/dist/core/format/src/kinds/deployments/schema.js +52 -0
  62. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  63. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  64. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  65. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  66. package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
  67. package/dist/core/format/src/kinds/integration/kind.js +49 -12
  68. package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
  69. package/dist/core/format/src/kinds/integration/policy.js +61 -2
  70. package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
  71. package/dist/core/format/src/kinds/integration/schema.js +132 -6
  72. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +13 -0
  73. package/dist/core/format/src/kinds/integration/sign-in-checks.js +120 -0
  74. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  75. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  76. package/dist/core/format/src/kinds/plugin/checks.js +7 -1
  77. package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
  78. package/dist/core/format/src/kinds/plugin/schema.js +2 -2
  79. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
  80. package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
  81. package/dist/core/format/src/kinds/routine/kind.js +38 -1
  82. package/dist/core/format/src/kinds/routine/schema.d.ts +10 -0
  83. package/dist/core/format/src/kinds/routine/schema.js +23 -1
  84. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  85. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  86. package/dist/core/format/src/kinds/workflow/schema.js +1 -1
  87. package/dist/core/format/src/kinds/workspace/kind.js +1 -1
  88. package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
  89. package/dist/core/format/src/kinds/workspace/schema.js +1 -1
  90. package/dist/core/format/src/shared/fields.d.ts +3 -6
  91. package/dist/core/format/src/shared/fields.js +33 -13
  92. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  93. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  94. package/dist/core/ports/src/blob-store.d.ts +12 -0
  95. package/dist/core/ports/src/blob-store.js +22 -0
  96. package/dist/core/ports/src/connector-client.d.ts +48 -4
  97. package/dist/core/ports/src/connector-client.js +17 -0
  98. package/dist/core/ports/src/definition-store.d.ts +23 -2
  99. package/dist/core/ports/src/harness-bridge-server.d.ts +12 -3
  100. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  101. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  102. package/dist/core/ports/src/harness.d.ts +46 -13
  103. package/dist/core/ports/src/harness.js +1 -1
  104. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  105. package/dist/core/ports/src/host-settings-store.js +106 -0
  106. package/dist/core/ports/src/index.d.ts +18 -10
  107. package/dist/core/ports/src/index.js +15 -7
  108. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  109. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  110. package/dist/core/ports/src/integration.d.ts +71 -7
  111. package/dist/core/ports/src/integration.js +22 -4
  112. package/dist/core/ports/src/llm-provider.d.ts +3 -1
  113. package/dist/core/ports/src/llm-provider.js +3 -0
  114. package/dist/core/ports/src/password-hasher.d.ts +36 -20
  115. package/dist/core/ports/src/port-versions.d.ts +7 -4
  116. package/dist/core/ports/src/port-versions.js +6 -0
  117. package/dist/core/ports/src/program-probe.d.ts +25 -2
  118. package/dist/core/ports/src/program-probe.js +1 -1
  119. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  120. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  121. package/dist/core/ports/src/record-store.d.ts +17 -0
  122. package/dist/core/ports/src/record-store.js +70 -0
  123. package/dist/core/ports/src/run-executor.d.ts +5 -4
  124. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  125. package/dist/core/ports/src/run-target-not-found.js +41 -0
  126. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  127. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  128. package/dist/core/ports/src/sandbox.d.ts +130 -13
  129. package/dist/core/ports/src/sandbox.js +38 -2
  130. package/dist/core/ports/src/secrets.d.ts +73 -0
  131. package/dist/core/ports/src/secrets.js +56 -0
  132. package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
  133. package/dist/core/ports/src/tool-approval-store.js +59 -0
  134. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  135. package/dist/core/ports/src/vcs-status.js +90 -0
  136. package/dist/core/std/src/amount.d.ts +13 -0
  137. package/dist/core/std/src/amount.js +22 -0
  138. package/dist/core/std/src/hidden-characters.d.ts +19 -0
  139. package/dist/core/std/src/hidden-characters.js +54 -0
  140. package/dist/core/std/src/index.d.ts +5 -0
  141. package/dist/core/std/src/index.js +5 -0
  142. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  143. package/dist/core/std/src/public-suffixes.generated.js +10429 -0
  144. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  145. package/dist/core/std/src/registrable-domain.js +62 -0
  146. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  147. package/dist/core/std/src/secret-variable-name.js +34 -0
  148. package/dist/core/std/src/site-name.d.ts +35 -0
  149. package/dist/core/std/src/site-name.js +111 -0
  150. package/dist/core/std/src/url-host.d.ts +35 -0
  151. package/dist/core/std/src/url-host.js +170 -0
  152. package/dist/testing/integration/src/load.js +3 -1
  153. package/package.json +2 -2
package/NOTICE CHANGED
@@ -1 +1,5 @@
1
1
  Halonic, Copyright 2026 The Halonic Authors
2
+
3
+ This product includes a copy of the Public Suffix List
4
+ (https://publicsuffix.org/), in packages/core/std/src/public-suffixes.generated.ts,
5
+ under the Mozilla Public License 2.0 (https://mozilla.org/MPL/2.0/).
package/README.md CHANGED
@@ -11,7 +11,7 @@ one:
11
11
  npm install --save-dev --save-exact @halonicjs/testing @halonicjs/adapters vitest
12
12
  ```
13
13
 
14
- ## `@halonicjs/testing/integration`
14
+ ## The conformance suite
15
15
 
16
16
  The suite loads the integration from its permission sheet through the kit's
17
17
  real loader, as Halonic does. It runs it with fake secret values, a replay
@@ -0,0 +1,19 @@
1
+ import type { HttpClient } from "../../../core/ports/src/index.js";
2
+ declare const addressChecking: unique symbol;
3
+ /**
4
+ * An `HttpClient` that checks addresses itself: on every request and every
5
+ * redirect hop it resolves the name, checks each address against the host's
6
+ * class, and connects only to an address it checked (I5 design, HAL-958
7
+ * section 3.8). A permission sheet names hosts only, so whatever sends an
8
+ * integration's requests must be one of these, or a public name that
9
+ * resolves to this computer would get through.
10
+ *
11
+ * The mark is a type, not a value: a plain `fetch` wrapper doesn't fit where
12
+ * this is asked for. Only an address-checking transport, such as the Node
13
+ * one, says it is one. A test that answers without a network asserts it with
14
+ * `as`, and says why.
15
+ */
16
+ export interface AddressCheckingHttpClient extends HttpClient {
17
+ readonly [addressChecking]: true;
18
+ }
19
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,3 @@
1
+ export type { AddressCheckingHttpClient } from "./address-checking.js";
1
2
  export { type AddressClass, addressAllowedFor, classifyAddress, type HostClass, } from "./address-class.js";
2
3
  export { type IpAddress, parseIpAddress } from "./ip-address.js";
@@ -0,0 +1,40 @@
1
+ import type { AuthPlacement, SecretPlacement, SignInPlacement } from "../../../core/ports/src/index.js";
2
+ import type { IntegrationPolicy } from "./policy.js";
3
+ /** The placement puts a secret, not a sign-in's token. */
4
+ export declare function isSecretPlacement(placement: AuthPlacement): placement is SecretPlacement;
5
+ /** The placement puts a sign-in's access token, not a secret. */
6
+ export declare function isSignInPlacement(placement: AuthPlacement): placement is SignInPlacement;
7
+ /**
8
+ * Copies the placements the integration's code gave into frozen objects of
9
+ * text fields, reading each field once. The kit checks and places only
10
+ * these copies: the code keeps its own objects and could change them, or
11
+ * give a getter, after the check and before the secret is placed. A field
12
+ * that isn't text is refused here, because an object could turn into other
13
+ * text each time it is read.
14
+ */
15
+ export declare function copyPlacements(policy: IntegrationPolicy, placements: readonly unknown[]): readonly AuthPlacement[];
16
+ /**
17
+ * Checks every placement against the sheet before a secret value or a token
18
+ * is read. Give it the copies from {@link copyPlacements}, never the code's
19
+ * own objects. Where a secret or token may go is for
20
+ * {@link checkPlacementHosts}.
21
+ */
22
+ export declare function checkPlacements(policy: IntegrationPolicy, placements: readonly AuthPlacement[]): void;
23
+ /**
24
+ * Checks that every placed secret or token may go to the request's first
25
+ * host, once the URL is parsed. {@link checkPlacements} has already run, so
26
+ * every secret and sign-in is declared.
27
+ */
28
+ export declare function checkPlacementHosts(policy: IntegrationPolicy, placements: readonly AuthPlacement[], url: URL): void;
29
+ /**
30
+ * Puts the secrets and tokens allowed for this hop's host into the headers
31
+ * and the form body. A placement whose secret or token may not go to this
32
+ * hop is left out, which happens after a redirect to another declared host.
33
+ *
34
+ * @param tokens the access tokens read for this hop, by sign-in
35
+ * @returns the form body to send, when a placement wrote into it
36
+ */
37
+ export declare function place(policy: IntegrationPolicy, placements: readonly AuthPlacement[], values: {
38
+ readonly secrets: ReadonlyMap<string, string>;
39
+ readonly tokens: ReadonlyMap<string, string>;
40
+ }, url: URL, headers: Headers, form: URLSearchParams | undefined): URLSearchParams | undefined;
@@ -0,0 +1,102 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ import { checkSecretHost, checkSecretPlacement, placeSecret, quoted } from "./secret-placement.js";
3
+ import { checkSignInPlacement, checkSignInPlacementHost, placeToken } from "./sign-in-placement.js";
4
+ /** The placement puts a secret, not a sign-in's token. */
5
+ export function isSecretPlacement(placement) {
6
+ return "secret" in placement;
7
+ }
8
+ /** The placement puts a sign-in's access token, not a secret. */
9
+ export function isSignInPlacement(placement) {
10
+ return "signIn" in placement;
11
+ }
12
+ /**
13
+ * Copies the placements the integration's code gave into frozen objects of
14
+ * text fields, reading each field once. The kit checks and places only
15
+ * these copies: the code keeps its own objects and could change them, or
16
+ * give a getter, after the check and before the secret is placed. A field
17
+ * that isn't text is refused here, because an object could turn into other
18
+ * text each time it is read.
19
+ */
20
+ export function copyPlacements(policy, placements) {
21
+ return Object.freeze(placements.map((placement) => copyPlacement(policy, placement)));
22
+ }
23
+ function copyPlacement(policy, placement) {
24
+ if (typeof placement !== "object" || placement === null) {
25
+ throw new IntegrationRefusedError("placement-not-in-sheet", `${policy.name}: a placement is not an object with text fields`);
26
+ }
27
+ const given = placement;
28
+ // The types say `secret` and `signIn` never appear together. If both do, nothing is placed, so a `signIn` key can't carry a secret past the secret check.
29
+ if ("secret" in given && "signIn" in given) {
30
+ throw new IntegrationRefusedError("placement-not-in-sheet", `${policy.name}: a placement names both a secret and a sign-in; it must name one`);
31
+ }
32
+ const kind = "signIn" in given ? "signIn" : "secret";
33
+ const owner = kind === "signIn" ? "sign-in" : "secret";
34
+ const name = given[kind];
35
+ const as = given.as;
36
+ if (typeof name !== "string")
37
+ throw notText(policy, `the ${owner}'s name`, owner);
38
+ if (typeof as !== "string")
39
+ throw notText(policy, `the "as" of the ${owner} ${quoted(name)}`, owner);
40
+ const copy = { [kind]: name, as };
41
+ for (const key of ["header", "prefix", "field"]) {
42
+ const value = given[key];
43
+ if (value === undefined)
44
+ continue;
45
+ if (typeof value !== "string")
46
+ throw notText(policy, `the "${key}" of the ${owner} ${quoted(name)}`, owner);
47
+ copy[key] = value;
48
+ }
49
+ // Whether the fields fit together is for `checkPlacements` to say.
50
+ return Object.freeze(copy);
51
+ }
52
+ /** A part of a placement that isn't text, named with the kind of placement it is in. */
53
+ function notText(policy, what, kind) {
54
+ return new IntegrationRefusedError("placement-not-in-sheet", `${policy.name}: ${what} in a ${kind} placement is not text`);
55
+ }
56
+ /**
57
+ * Checks every placement against the sheet before a secret value or a token
58
+ * is read. Give it the copies from {@link copyPlacements}, never the code's
59
+ * own objects. Where a secret or token may go is for
60
+ * {@link checkPlacementHosts}.
61
+ */
62
+ export function checkPlacements(policy, placements) {
63
+ for (const placement of placements) {
64
+ if (isSecretPlacement(placement))
65
+ checkSecretPlacement(policy, placement);
66
+ else
67
+ checkSignInPlacement(policy, placement);
68
+ }
69
+ }
70
+ /**
71
+ * Checks that every placed secret or token may go to the request's first
72
+ * host, once the URL is parsed. {@link checkPlacements} has already run, so
73
+ * every secret and sign-in is declared.
74
+ */
75
+ export function checkPlacementHosts(policy, placements, url) {
76
+ for (const placement of placements) {
77
+ if (isSecretPlacement(placement))
78
+ checkSecretHost(policy, placement, url);
79
+ else
80
+ checkSignInPlacementHost(policy, placement, url);
81
+ }
82
+ }
83
+ /**
84
+ * Puts the secrets and tokens allowed for this hop's host into the headers
85
+ * and the form body. A placement whose secret or token may not go to this
86
+ * hop is left out, which happens after a redirect to another declared host.
87
+ *
88
+ * @param tokens the access tokens read for this hop, by sign-in
89
+ * @returns the form body to send, when a placement wrote into it
90
+ */
91
+ export function place(policy, placements, values, url, headers, form) {
92
+ let body = form;
93
+ for (const placement of placements) {
94
+ if (isSecretPlacement(placement)) {
95
+ body = placeSecret(policy, placement, values.secrets.get(placement.secret), url, headers, body);
96
+ }
97
+ else {
98
+ placeToken(placement, values.tokens.get(placement.signIn), headers);
99
+ }
100
+ }
101
+ return body;
102
+ }
@@ -0,0 +1,28 @@
1
+ import type { SignInTokens } from "../../../core/ports/src/index.js";
2
+ import { type SecretForms, type SecretOnWire } from "./secret-filter.js";
3
+ /**
4
+ * The forms the filter looks for now. Sign-in tokens change while an
5
+ * integration runs, so a filter outside the kit, such as the runner bridge's,
6
+ * asks for them each time it filters instead of keeping the forms it built
7
+ * at the start. The same `SecretForms` object comes back until a value changes.
8
+ */
9
+ export type CurrentSecretForms = () => SecretForms;
10
+ /**
11
+ * The forms of `secrets` and of every value the sign-ins' `filterValues`
12
+ * lists now: the access tokens not yet expired, the refresh token and the
13
+ * client secret. A sign-in value is matched in every form a secret is.
14
+ *
15
+ * @example
16
+ * const current = currentSecretForms([{ value: key }], signIns.tokens);
17
+ * removeSecrets(text, current());
18
+ */
19
+ export declare function currentSecretForms(secrets: readonly SecretOnWire[], signIns?: Pick<SignInTokens, "filterValues">): CurrentSecretForms;
20
+ /**
21
+ * A stream step that removes the current secrets, for the bridge's stderr.
22
+ * When the forms change, a value that began in the bytes held back and ends in
23
+ * the next piece is still found: the held bytes go through the new forms again.
24
+ *
25
+ * @example
26
+ * runner.stderr.pipeThrough(removeCurrentSecretsStream(current))
27
+ */
28
+ export declare function removeCurrentSecretsStream(current: CurrentSecretForms): TransformStream<Uint8Array, Uint8Array>;
@@ -0,0 +1,60 @@
1
+ import { SecretRemover, secretForms, } from "./secret-filter.js";
2
+ /**
3
+ * The forms of `secrets` and of every value the sign-ins' `filterValues`
4
+ * lists now: the access tokens not yet expired, the refresh token and the
5
+ * client secret. A sign-in value is matched in every form a secret is.
6
+ *
7
+ * @example
8
+ * const current = currentSecretForms([{ value: key }], signIns.tokens);
9
+ * removeSecrets(text, current());
10
+ */
11
+ export function currentSecretForms(secrets, signIns) {
12
+ const fixed = secretForms(secrets);
13
+ if (signIns === undefined) {
14
+ return () => fixed;
15
+ }
16
+ let listed = [];
17
+ let forms = fixed;
18
+ return () => {
19
+ const values = signIns.filterValues();
20
+ if (!sameValues(values, listed)) {
21
+ listed = [...values];
22
+ forms = secretForms([...secrets, ...values.map((value) => ({ value }))]);
23
+ }
24
+ return forms;
25
+ };
26
+ }
27
+ function sameValues(a, b) {
28
+ return a.length === b.length && a.every((value, index) => value === b[index]);
29
+ }
30
+ /**
31
+ * A stream step that removes the current secrets, for the bridge's stderr.
32
+ * When the forms change, a value that began in the bytes held back and ends in
33
+ * the next piece is still found: the held bytes go through the new forms again.
34
+ *
35
+ * @example
36
+ * runner.stderr.pipeThrough(removeCurrentSecretsStream(current))
37
+ */
38
+ export function removeCurrentSecretsStream(current) {
39
+ let forms = current();
40
+ let remover = new SecretRemover(forms);
41
+ return new TransformStream({
42
+ transform(piece, controller) {
43
+ const now = current();
44
+ if (now !== forms) {
45
+ const held = remover.flush();
46
+ forms = now;
47
+ remover = new SecretRemover(now);
48
+ enqueueIfAny(controller, remover.push(held));
49
+ }
50
+ enqueueIfAny(controller, remover.push(piece));
51
+ },
52
+ flush(controller) {
53
+ enqueueIfAny(controller, remover.flush());
54
+ },
55
+ });
56
+ }
57
+ function enqueueIfAny(controller, bytes) {
58
+ if (bytes.length > 0)
59
+ controller.enqueue(bytes);
60
+ }
@@ -2,7 +2,8 @@ import type { IntegrationSheet } from "../../../core/format/src/integration/inde
2
2
  import { type Integration } from "../../../core/ports/src/index.js";
3
3
  import type { LoadProblem } from "./load-problem.js";
4
4
  /**
5
- * Where the integration's code differs from its permission sheet: the kit
5
+ * Where the integration's code differs from its permission sheet, or the sheet
6
+ * needs a newer kit than this Halonic offers: the kit
6
7
  * version, the name, the version, and each tool's text, `risk` and
7
8
  * `untrusted`. The user approves the sheet, so the code must be exactly what
8
9
  * it says. Empty when they match. Only what the code declares is read, so a
@@ -1,6 +1,7 @@
1
1
  import { integrationVersion } from "../../../core/ports/src/index.js";
2
2
  /**
3
- * Where the integration's code differs from its permission sheet: the kit
3
+ * Where the integration's code differs from its permission sheet, or the sheet
4
+ * needs a newer kit than this Halonic offers: the kit
4
5
  * version, the name, the version, and each tool's text, `risk` and
5
6
  * `untrusted`. The user approves the sheet, so the code must be exactly what
6
7
  * it says. Empty when they match. Only what the code declares is read, so a
@@ -12,8 +13,8 @@ import { integrationVersion } from "../../../core/ports/src/index.js";
12
13
  export function declarationProblems(sheet, integration) {
13
14
  const problems = [];
14
15
  const add = (code, path, message) => problems.push({ code, path, message: `${sheet.id}: ${message}` });
15
- if (sheet.kit !== integrationVersion) {
16
- add("kit-version", ["kit"], `built against kit ${sheet.kit}, but this Halonic offers kit ${integrationVersion}`);
16
+ if (sheet.kit > integrationVersion) {
17
+ add("kit-version", ["kit"], `this integration needs a newer version of Halonic (it is built against kit ${sheet.kit}, and this Halonic offers kit ${integrationVersion})`);
17
18
  }
18
19
  if (integration.name !== sheet.id) {
19
20
  add("name-differs", ["id"], `the code is named "${integration.name}"`);
@@ -1,4 +1,4 @@
1
- import type { HttpClient, IntegrationHost, Secrets, TokenStore } from "../../../core/ports/src/index.js";
1
+ import type { HttpClient, IntegrationHost, Secrets, SignInTokens, TokenStore } from "../../../core/ports/src/index.js";
2
2
  import { type RequestLimits } from "./limited-http.js";
3
3
  import type { IntegrationPolicy } from "./policy.js";
4
4
  import { RequestLog } from "./request-log.js";
@@ -8,6 +8,12 @@ export interface IntegrationHostOptions {
8
8
  readonly transport: HttpClient;
9
9
  readonly secrets: Secrets;
10
10
  readonly tokens: TokenStore;
11
+ /**
12
+ * Where the kit gets the access tokens of the sheet's sign-ins, and tells
13
+ * about a 401. Without it, a request that places a token is refused as
14
+ * `sign-in-needed`.
15
+ */
16
+ readonly signInTokens?: SignInTokens;
11
17
  readonly settings?: Readonly<Record<string, unknown>>;
12
18
  readonly limits?: RequestLimits;
13
19
  readonly now?: () => number;
@@ -17,6 +17,7 @@ export function createIntegrationHost(options) {
17
17
  transport: options.transport,
18
18
  secrets: options.secrets,
19
19
  log,
20
+ ...(options.signInTokens ? { signInTokens: options.signInTokens } : {}),
20
21
  ...(options.limits ? { limits: options.limits } : {}),
21
22
  ...(options.now ? { now: options.now } : {}),
22
23
  });
@@ -1,3 +1,5 @@
1
+ export type { AddressCheckingHttpClient } from "../../http-kit/src/index.js";
2
+ export { type CurrentSecretForms, currentSecretForms, removeCurrentSecretsStream, } from "./current-secret-forms.js";
1
3
  export { declarationProblems } from "./declaration.js";
2
4
  export { type CreatedIntegrationHost, createIntegrationHost, type IntegrationHostOptions, } from "./host.js";
3
5
  export { IntegrationRefusedError, IntegrationTimeoutError, type RefusalCode, } from "@halonicjs/adapters/integration-kit";
@@ -6,7 +8,7 @@ export { createLimitedHttpClient, type LimitedHttpOptions, type RequestLimits, }
6
8
  export type { LoadProblem } from "./load-problem.js";
7
9
  export { type IntegrationSource, type LoadedIntegration, type LoadIntegrationOptions, loadIntegration, type PreparedIntegration, type PrepareIntegrationOptions, prepareIntegration, providerChoices, type WorkspaceChoices, } from "./loader.js";
8
10
  export { pluginLoadProblems } from "./plugin-load.js";
9
- export { allowedUrl, type DeclaredPlacement, type DeclaredSecret, type IntegrationPolicy, namePattern, } from "./policy.js";
11
+ export { allowedUrl, type DeclaredPlacement, type DeclaredSecret, type DeclaredSignIn, type DeclaredSignInPlacement, type IntegrationPolicy, namePattern, } from "./policy.js";
10
12
  export { maxRequestBodyBytes } from "./request-body.js";
11
13
  export { RequestLog, type RequestLogEntry } from "./request-log.js";
12
14
  export { scopedTokens, storedTokenName } from "./scoped-tokens.js";
@@ -6,6 +6,7 @@
6
6
  // outside the conformance suite's bundle and points it at the published kit;
7
7
  // it fails when host code imports a file inside the entry's folder instead
8
8
  // of the entry itself. Internal code imports by relative path.
9
+ export { currentSecretForms, removeCurrentSecretsStream, } from "./current-secret-forms.js";
9
10
  export { declarationProblems } from "./declaration.js";
10
11
  export { createIntegrationHost, } from "./host.js";
11
12
  export { IntegrationRefusedError, IntegrationTimeoutError, } from "@halonicjs/adapters/integration-kit";
@@ -1,8 +1,10 @@
1
1
  import type { RefusalCode } from "@halonicjs/adapters/integration-kit";
2
2
  /**
3
3
  * The refusal codes that mean the integration tried to get a secret out:
4
- * it carried a secret value in its own request, or it asked the kit to
5
- * place a secret somewhere its permission sheet doesn't say. A connector
4
+ * it carried a secret value in its own request, it asked the kit to
5
+ * place a secret or a sign-in's token somewhere its permission sheet doesn't
6
+ * say, or it asked for a client secret, which only Halonic's sign-in code
7
+ * may send. A connector
6
8
  * that gets one of these should be paused, not just shown the error. Every
7
9
  * other code is an ordinary mistake, such as a host the sheet doesn't list
8
10
  * or a body that is too large, or comes from the server, such as
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * The refusal codes that mean the integration tried to get a secret out:
3
- * it carried a secret value in its own request, or it asked the kit to
4
- * place a secret somewhere its permission sheet doesn't say. A connector
3
+ * it carried a secret value in its own request, it asked the kit to
4
+ * place a secret or a sign-in's token somewhere its permission sheet doesn't
5
+ * say, or it asked for a client secret, which only Halonic's sign-in code
6
+ * may send. A connector
5
7
  * that gets one of these should be paused, not just shown the error. Every
6
8
  * other code is an ordinary mistake, such as a host the sheet doesn't list
7
9
  * or a body that is too large, or comes from the server, such as
@@ -13,4 +15,5 @@
13
15
  export const leakAttemptCodes = Object.freeze([
14
16
  "secret-in-request",
15
17
  "placement-not-in-sheet",
18
+ "secret-sign-in-only",
16
19
  ]);
@@ -1,4 +1,4 @@
1
- import type { HttpClient, IntegrationHttpClient, Secrets } from "../../../core/ports/src/index.js";
1
+ import type { HttpClient, IntegrationHttpClient, Secrets, SignInTokens } from "../../../core/ports/src/index.js";
2
2
  import { type IntegrationPolicy } from "./policy.js";
3
3
  import type { RequestLog } from "./request-log.js";
4
4
  /**
@@ -31,6 +31,12 @@ export interface LimitedHttpOptions {
31
31
  readonly transport: HttpClient;
32
32
  /** Where the kit reads the values of the secrets it places. */
33
33
  readonly secrets: Secrets;
34
+ /**
35
+ * Where the kit gets the access token of a sign-in it places, and what it
36
+ * tells when a server answers 401. Without it, a request that places a
37
+ * token is refused as `sign-in-needed`.
38
+ */
39
+ readonly signInTokens?: SignInTokens;
34
40
  readonly log: RequestLog;
35
41
  readonly limits?: RequestLimits;
36
42
  /** Milliseconds for the request log's timings. Default `Date.now`. */
@@ -1,3 +1,4 @@
1
+ import { checkPlacementHosts, checkPlacements, isSecretPlacement, isSignInPlacement, place, } from "./auth-placement.js";
1
2
  import { IntegrationRefusedError, IntegrationTimeoutError } from "@halonicjs/adapters/integration-kit";
2
3
  import { copyRequest } from "./own-request.js";
3
4
  import { allowedUrl } from "./policy.js";
@@ -5,7 +6,8 @@ import { bodyBytes, checkBody, requestBodyLimit, requestTooLarge, toForm, } from
5
6
  import { guardBody, untilAborted } from "./response-body.js";
6
7
  import { removeSecretsFromError, secretForms } from "./secret-filter.js";
7
8
  import { carriedForms, readDeclaredSecrets, refuseCarriedSecrets, refuseRedirectCarryingSecrets, SecretInRequestError, } from "./secret-in-request.js";
8
- import { checkPlacementHosts, checkPlacements, place, readSecrets } from "./secret-placement.js";
9
+ import { readSecrets } from "./secret-placement.js";
10
+ import { readTokens, reportRejected } from "./sign-in-placement.js";
9
11
  const redirectStatuses = new Set([301, 302, 303, 307, 308]);
10
12
  /** Headers a browser drops when a redirect leaves the origin; the kit does the same. */
11
13
  const originBoundHeaders = ["authorization", "cookie", "proxy-authorization"];
@@ -33,7 +35,7 @@ export function createLimitedHttpClient(options) {
33
35
  // Needs no secret, so a placement the sheet doesn't allow is refused before any is read.
34
36
  checkPlacements(options.policy, own.placements);
35
37
  const declared = await readDeclaredSecrets(options.policy, options.secrets);
36
- const carried = carriedForms(declared.values());
38
+ const carried = carriedForms([...declared.values(), ...signInValues(options)]);
37
39
  refuseCarriedSecrets(options.policy, carried, {
38
40
  method: own.givenMethod,
39
41
  sentMethod: own.method,
@@ -65,6 +67,10 @@ export function createLimitedHttpClient(options) {
65
67
  },
66
68
  };
67
69
  }
70
+ /** Every value the sign-ins' tokens say the filter must remove: tokens not yet expired, refresh tokens, client secrets. */
71
+ function signInValues(options) {
72
+ return options.signInTokens?.filterValues() ?? [];
73
+ }
68
74
  /** What the log shows of a request that failed before the secret check passed. */
69
75
  const unchecked = { method: "", host: "", path: "" };
70
76
  async function send(options, own, { declared, carried }) {
@@ -96,13 +102,18 @@ async function send(options, own, { declared, carried }) {
96
102
  onIdle: () => timers.stop("no data", limits.idleTimeoutMs ?? 60_000),
97
103
  done: () => clearTimeout(timers.total),
98
104
  // Every declared secret, not only the placed ones: the bridge filters the same way.
99
- secrets: secretForms([...declared].map(([secret, value]) => ({
100
- value,
101
- placements: placements.filter((placement) => placement.secret === secret),
102
- }))),
105
+ secrets: filterForms(options, placements, declared, new Map()),
103
106
  };
104
107
  try {
105
- return await followHops(options, { hop, values, carried, guard, maxBodyBytes, timers });
108
+ return await followHops(options, {
109
+ hop,
110
+ values,
111
+ declared,
112
+ carried,
113
+ guard,
114
+ maxBodyBytes,
115
+ timers,
116
+ });
106
117
  }
107
118
  catch (error) {
108
119
  clearTimeout(timers.headers);
@@ -123,14 +134,43 @@ function startTimers(policy, hop, limits, signal) {
123
134
  stop,
124
135
  };
125
136
  }
137
+ /**
138
+ * Every form of the values that must not reach the integration or leave in
139
+ * its own requests: the declared secrets (with where this request places
140
+ * them), the sign-ins' filter values, and the tokens this hop places.
141
+ */
142
+ function filterForms(options, placements, declared, tokens) {
143
+ const placedAs = (name, isPlaced) => placements.filter((placement) => isPlaced(placement) && placementName(placement) === name);
144
+ return secretForms([
145
+ ...[...declared].map(([secret, value]) => ({
146
+ value,
147
+ placements: placedAs(secret, isSecretPlacement),
148
+ })),
149
+ ...signInValues(options).map((value) => ({ value })),
150
+ ...[...tokens].map(([signIn, value]) => ({
151
+ value,
152
+ placements: placedAs(signIn, isSignInPlacement),
153
+ })),
154
+ ]);
155
+ }
156
+ /** The name of the secret or sign-in a placement is for. */
157
+ function placementName(placement) {
158
+ return isSecretPlacement(placement) ? placement.secret : placement.signIn;
159
+ }
126
160
  /** Sends the request, then each redirect hop, until an answer that isn't one. */
127
161
  async function followHops(options, context) {
128
162
  const { policy, limits = {} } = options;
129
- const { hop, values, carried, guard, maxBodyBytes, timers } = context;
163
+ const { hop, values, declared, guard, maxBodyBytes, timers } = context;
130
164
  const maxRedirects = limits.maxRedirects ?? 5;
131
165
  for (let count = 0;; count++) {
166
+ const tokens = await readTokens(policy, options.signInTokens, hop.placements.filter(isSignInPlacement), hop.url, timers.combined);
167
+ if (hop.placements.some(isSignInPlacement)) {
168
+ // A refresh may have issued a token the filter didn't know when the request started.
169
+ guard.secrets = filterForms(options, hop.placements, declared, tokens);
170
+ context.carried = carriedForms([...declared.values(), ...signInValues(options)]);
171
+ }
132
172
  const headers = new Headers(hop.headers);
133
- const placedForm = place(policy, hop.placements, values, hop.url, headers, hop.form);
173
+ const placedForm = place(policy, hop.placements, { secrets: values, tokens }, hop.url, headers, hop.form);
134
174
  const body = placedForm ?? hop.body;
135
175
  if (bodyBytes(body) > maxBodyBytes)
136
176
  throw requestTooLarge(policy, hop.url, maxBodyBytes);
@@ -141,6 +181,9 @@ async function followHops(options, context) {
141
181
  redirect: "manual",
142
182
  signal: timers.combined,
143
183
  }), timers.combined);
184
+ // Only for a token this hop placed: a 401 from any other hop says nothing about it.
185
+ if (response.status === 401)
186
+ reportRejected(options.signInTokens, tokens);
144
187
  const location = response.headers.get("location");
145
188
  if (!redirectStatuses.has(response.status) || location === null) {
146
189
  clearTimeout(timers.headers);
@@ -150,7 +193,7 @@ async function followHops(options, context) {
150
193
  if (count >= maxRedirects) {
151
194
  throw new IntegrationRefusedError("too-many-redirects", `${policy.name}: ${hop.url.host}${hop.url.pathname} redirected more than ${maxRedirects} times`);
152
195
  }
153
- refuseRedirectCarryingSecrets(policy, carried, location, hop.url);
196
+ refuseRedirectCarryingSecrets(policy, context.carried, location, hop.url);
154
197
  follow(hop, response.status, allowedUrl(policy, location, hop.url));
155
198
  }
156
199
  }
@@ -1,6 +1,8 @@
1
+ import type { AddressCheckingHttpClient } from "../../http-kit/src/index.js";
1
2
  import { type IntegrationSheet } from "../../../core/format/src/integration/index.js";
2
- import { type HttpClient, type Integration, type IntegrationHost, type ProviderConfig, type Secrets, type TokenStore } from "../../../core/ports/src/index.js";
3
+ import { type Integration, type IntegrationHost, type ProviderConfig, type Secrets, type SignInTokens, type TokenStore } from "../../../core/ports/src/index.js";
3
4
  import { type Result } from "../../../core/std/src/index.js";
5
+ import { type CurrentSecretForms } from "./current-secret-forms.js";
4
6
  import type { LoadProblem } from "./load-problem.js";
5
7
  import type { RequestLog } from "./request-log.js";
6
8
  import type { SecretOnWire } from "./secret-filter.js";
@@ -20,6 +22,13 @@ export interface IntegrationSource {
20
22
  * step. The loader refuses it when the sheet has changed since.
21
23
  */
22
24
  readonly approvedSheet?: unknown;
25
+ /**
26
+ * `true` for a plugin's backend, whose sheet's id is the plugin's. The
27
+ * secrets it picks are then read as that plugin's own, `plugin__<id>__<name>`,
28
+ * and only those, never as a workspace's picks, which can't name a plugin's.
29
+ * The names come from the plugin's manifest, never from a workspace.
30
+ */
31
+ readonly plugin?: boolean;
23
32
  }
24
33
  /** What the workspace chose for one integration. */
25
34
  export interface WorkspaceChoices {
@@ -36,9 +45,20 @@ export interface WorkspaceChoices {
36
45
  export interface LoadIntegrationOptions {
37
46
  readonly source: IntegrationSource;
38
47
  readonly choices?: WorkspaceChoices;
39
- readonly transport: HttpClient;
48
+ /**
49
+ * What sends the requests. The sheet names hosts only, so it must check
50
+ * the addresses a name resolves to itself: the Node one from
51
+ * `createNodeHttpClient`, never a plain `fetch` wrapper.
52
+ */
53
+ readonly transport: AddressCheckingHttpClient;
40
54
  readonly secrets: Secrets;
41
55
  readonly tokens: TokenStore;
56
+ /**
57
+ * The access tokens of the sheet's sign-ins, from the host's
58
+ * `createIntegrationSignIns`. Without it a request that places a sign-in's
59
+ * token is refused as `sign-in-needed`. The integration never sees it.
60
+ */
61
+ readonly signInTokens?: SignInTokens;
42
62
  /** What this runtime offers beyond HTTP, for the sheet's `needs`, such as `process`. Default none. */
43
63
  readonly capabilities?: readonly string[];
44
64
  readonly now?: () => number;
@@ -68,6 +88,13 @@ export interface PreparedIntegration extends Omit<LoadedIntegration, "integratio
68
88
  * filtered too. Only Halonic's side ever calls it.
69
89
  */
70
90
  readonly readSecrets: () => Promise<SecretOnWire[]>;
91
+ /**
92
+ * What the runner bridge filters with: the picked secrets read now, and
93
+ * every value the sign-in tokens list, read again each time the filter is
94
+ * used, so a token a refresh issues later is removed too. Call it for each
95
+ * runner start, like {@link PreparedIntegration.readSecrets}.
96
+ */
97
+ readonly currentSecretForms: () => Promise<CurrentSecretForms>;
71
98
  }
72
99
  /**
73
100
  * Checks an integration against its permission sheet and builds its host. The