@sanoma-ai/workflows 0.0.0-stage → 0.2.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 +105 -0
- package/README.md +544 -2
- package/dist/apply-steps.d.ts +6 -0
- package/dist/apply-steps.js +93 -0
- package/dist/apply-steps.js.map +1 -0
- package/dist/apply.d.ts +197 -0
- package/dist/apply.js +470 -0
- package/dist/apply.js.map +1 -0
- package/dist/approvals.d.ts +46 -0
- package/dist/approvals.js +111 -0
- package/dist/approvals.js.map +1 -0
- package/dist/ast.d.ts +57 -0
- package/dist/ast.js +81 -0
- package/dist/ast.js.map +1 -0
- package/dist/call.d.ts +37 -0
- package/dist/call.js +417 -0
- package/dist/call.js.map +1 -0
- package/dist/client.d.ts +203 -0
- package/dist/client.js +457 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +126 -0
- package/dist/config.js +264 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +55 -0
- package/dist/credentials.js +261 -0
- package/dist/credentials.js.map +1 -0
- package/dist/cucumber.d.ts +64 -0
- package/dist/cucumber.js +158 -0
- package/dist/cucumber.js.map +1 -0
- package/dist/datafile.d.ts +71 -0
- package/dist/datafile.js +380 -0
- package/dist/datafile.js.map +1 -0
- package/dist/db.d.ts +58 -0
- package/dist/db.js +179 -0
- package/dist/db.js.map +1 -0
- package/dist/define.d.ts +205 -0
- package/dist/define.js +103 -0
- package/dist/define.js.map +1 -0
- package/dist/describe.d.ts +141 -0
- package/dist/describe.js +135 -0
- package/dist/describe.js.map +1 -0
- package/dist/drift.d.ts +127 -0
- package/dist/drift.js +167 -0
- package/dist/drift.js.map +1 -0
- package/dist/env.d.ts +49 -0
- package/dist/env.js +83 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +88 -0
- package/dist/errors.js +148 -0
- package/dist/errors.js.map +1 -0
- package/dist/expectations.d.ts +26 -0
- package/dist/expectations.js +162 -0
- package/dist/expectations.js.map +1 -0
- package/dist/fake.d.ts +55 -0
- package/dist/fake.js +87 -0
- package/dist/fake.js.map +1 -0
- package/dist/fill.d.ts +9 -0
- package/dist/fill.js +17 -0
- package/dist/fill.js.map +1 -0
- package/dist/host.d.ts +56 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger.d.ts +217 -0
- package/dist/ledger.js +251 -0
- package/dist/ledger.js.map +1 -0
- package/dist/lint.d.ts +32 -0
- package/dist/lint.js +168 -0
- package/dist/lint.js.map +1 -0
- package/dist/lockfile.d.ts +36 -0
- package/dist/lockfile.js +69 -0
- package/dist/lockfile.js.map +1 -0
- package/dist/log.d.ts +24 -0
- package/dist/log.js +83 -0
- package/dist/log.js.map +1 -0
- package/dist/op.d.ts +260 -0
- package/dist/op.js +188 -0
- package/dist/op.js.map +1 -0
- package/dist/outline.d.ts +179 -0
- package/dist/outline.js +506 -0
- package/dist/outline.js.map +1 -0
- package/dist/paths.d.ts +11 -0
- package/dist/paths.js +30 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugin.d.ts +28 -0
- package/dist/plugin.js +25 -0
- package/dist/plugin.js.map +1 -0
- package/dist/policy.d.ts +114 -0
- package/dist/policy.js +60 -0
- package/dist/policy.js.map +1 -0
- package/dist/resource.d.ts +378 -0
- package/dist/resource.js +430 -0
- package/dist/resource.js.map +1 -0
- package/dist/resources.d.ts +77 -0
- package/dist/resources.js +244 -0
- package/dist/resources.js.map +1 -0
- package/dist/run.d.ts +101 -0
- package/dist/run.js +7 -0
- package/dist/run.js.map +1 -0
- package/dist/sandbox.d.ts +33 -0
- package/dist/sandbox.js +127 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/scenario.d.ts +221 -0
- package/dist/scenario.js +1104 -0
- package/dist/scenario.js.map +1 -0
- package/dist/scenarios.d.ts +55 -0
- package/dist/scenarios.js +71 -0
- package/dist/scenarios.js.map +1 -0
- package/dist/secret.d.ts +42 -0
- package/dist/secret.js +58 -0
- package/dist/secret.js.map +1 -0
- package/dist/shared.d.ts +69 -0
- package/dist/shared.js +84 -0
- package/dist/shared.js.map +1 -0
- package/dist/source.d.ts +58 -0
- package/dist/source.js +54 -0
- package/dist/source.js.map +1 -0
- package/dist/steps.d.ts +76 -0
- package/dist/steps.js +23 -0
- package/dist/steps.js.map +1 -0
- package/dist/version.d.ts +29 -0
- package/dist/version.js +76 -0
- package/dist/version.js.map +1 -0
- package/dist/worker.d.ts +37 -0
- package/dist/worker.js +228 -0
- package/dist/worker.js.map +1 -0
- package/dist/writer.d.ts +35 -0
- package/dist/writer.js +201 -0
- package/dist/writer.js.map +1 -0
- package/oxlint.json +128 -0
- package/package.json +96 -3
- package/src/apply-steps.ts +110 -0
- package/src/apply.ts +626 -0
- package/src/approvals.ts +157 -0
- package/src/ast.ts +115 -0
- package/src/call.ts +483 -0
- package/src/client.ts +604 -0
- package/src/config.ts +404 -0
- package/src/credentials.ts +296 -0
- package/src/cucumber.ts +230 -0
- package/src/datafile.ts +481 -0
- package/src/db.ts +197 -0
- package/src/define.ts +285 -0
- package/src/describe.ts +282 -0
- package/src/drift.ts +259 -0
- package/src/env.ts +122 -0
- package/src/errors.ts +202 -0
- package/src/expectations.ts +191 -0
- package/src/fake.ts +156 -0
- package/src/fill.ts +24 -0
- package/src/host.ts +96 -0
- package/src/index.ts +143 -0
- package/src/ledger.ts +419 -0
- package/src/lint.ts +208 -0
- package/src/lockfile.ts +95 -0
- package/src/log.ts +82 -0
- package/src/op.ts +402 -0
- package/src/outline.ts +620 -0
- package/src/paths.ts +32 -0
- package/src/plugin.ts +37 -0
- package/src/policy.ts +139 -0
- package/src/resource.ts +670 -0
- package/src/resources.ts +311 -0
- package/src/run.ts +106 -0
- package/src/sandbox.ts +161 -0
- package/src/scenario.ts +1365 -0
- package/src/scenarios.ts +111 -0
- package/src/secret.ts +92 -0
- package/src/shared.ts +126 -0
- package/src/source.ts +82 -0
- package/src/steps.ts +90 -0
- package/src/version.ts +86 -0
- package/src/worker.ts +264 -0
- package/src/writer.ts +225 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { RunSummary, SanomaClient } from "./client.ts";
|
|
2
|
+
import type { ResolvedConfig } from "./config.ts";
|
|
3
|
+
import type { Fake } from "./fake.ts";
|
|
4
|
+
import type { LedgerRecord } from "./ledger.ts";
|
|
5
|
+
import type { Driver } from "./op.ts";
|
|
6
|
+
import type { Seed } from "./steps.ts";
|
|
7
|
+
/** One step of a scenario, as written, for a list and for marking the graph node it is about. */
|
|
8
|
+
export interface ScenarioStep {
|
|
9
|
+
text: string;
|
|
10
|
+
kind: "given" | "when" | "then";
|
|
11
|
+
/** The operation the step is about, when it names one. */
|
|
12
|
+
op?: string;
|
|
13
|
+
/** For a `Then` step about a step by its name (`step "Draft the post" was called`): that name. */
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* For a `Then` step about an operation, or a step by its name: true when it expects a call (or
|
|
17
|
+
* a run), false for `was not called` (or `ran 0 times`).
|
|
18
|
+
*/
|
|
19
|
+
called?: boolean;
|
|
20
|
+
/** For a `Then` step about the policy's decision on an operation: `was denied`, or `was held for`. */
|
|
21
|
+
decision?: "denied" | "held";
|
|
22
|
+
/** For a `Given` that injects a fault into the operation's next call (`fails once` and the like), rather than seeding it. */
|
|
23
|
+
fault?: true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A fake's state to seed through one of its operations (`as` names what the call returns, for
|
|
27
|
+
* an operation's own test), a fault to inject into its next call, or an object a vendor's fake
|
|
28
|
+
* holds: `resource` is its type's id (`github.repository`, its `vendor` and `type`) and `name`
|
|
29
|
+
* its import id, with `fields` to set on it (put, when the vendor has none) or `gone` to remove it.
|
|
30
|
+
*/
|
|
31
|
+
export type Given = {
|
|
32
|
+
step: string;
|
|
33
|
+
op: string;
|
|
34
|
+
input: unknown;
|
|
35
|
+
as?: string;
|
|
36
|
+
} | {
|
|
37
|
+
step: string;
|
|
38
|
+
op: string;
|
|
39
|
+
fault: Fault;
|
|
40
|
+
} | {
|
|
41
|
+
step: string;
|
|
42
|
+
resource: string;
|
|
43
|
+
vendor: string;
|
|
44
|
+
type: string;
|
|
45
|
+
name: string;
|
|
46
|
+
fields: Record<string, unknown>;
|
|
47
|
+
} | {
|
|
48
|
+
step: string;
|
|
49
|
+
resource: string;
|
|
50
|
+
vendor: string;
|
|
51
|
+
type: string;
|
|
52
|
+
name: string;
|
|
53
|
+
gone: true;
|
|
54
|
+
};
|
|
55
|
+
/** How one approval is decided; `approval` is its title or its id. */
|
|
56
|
+
export interface Decision {
|
|
57
|
+
step: string;
|
|
58
|
+
approval: string;
|
|
59
|
+
decision: "approve" | "reject";
|
|
60
|
+
by: string;
|
|
61
|
+
note?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What the run should do: call an operation (with at least this input) or not, run the step
|
|
65
|
+
* `name`d in the workflow's outline or not, or a number of `times`, have the policy deny an
|
|
66
|
+
* operation (`denied`) or hold one for an approver (`held`), end a certain way, for a drift
|
|
67
|
+
* run, report the resource `declared` (`<file>#<export>`) clean, gone, absent, or drifted in a
|
|
68
|
+
* field, or for an apply run, create it, or leave it bound to an object (`bound`, its vendor's id).
|
|
69
|
+
* A step whose own code checks the run (a connector's or the company's, or an operation's own
|
|
70
|
+
* test's) is `custom`, with what it is about.
|
|
71
|
+
*/
|
|
72
|
+
export type Expectation = {
|
|
73
|
+
step: string;
|
|
74
|
+
op: string;
|
|
75
|
+
input?: unknown;
|
|
76
|
+
called: boolean;
|
|
77
|
+
} | {
|
|
78
|
+
step: string;
|
|
79
|
+
name: string;
|
|
80
|
+
input?: unknown;
|
|
81
|
+
called: boolean;
|
|
82
|
+
} | {
|
|
83
|
+
step: string;
|
|
84
|
+
name: string;
|
|
85
|
+
times: number;
|
|
86
|
+
} | {
|
|
87
|
+
step: string;
|
|
88
|
+
op: string;
|
|
89
|
+
decision: "denied";
|
|
90
|
+
} | {
|
|
91
|
+
step: string;
|
|
92
|
+
op: string;
|
|
93
|
+
decision: "held";
|
|
94
|
+
approver: string;
|
|
95
|
+
} | {
|
|
96
|
+
step: string;
|
|
97
|
+
outcome: "finished" | "failed";
|
|
98
|
+
code?: string;
|
|
99
|
+
} | {
|
|
100
|
+
step: string;
|
|
101
|
+
declared: string;
|
|
102
|
+
status: "clean" | "gone" | "absent";
|
|
103
|
+
} | {
|
|
104
|
+
step: string;
|
|
105
|
+
declared: string;
|
|
106
|
+
status: "drifted";
|
|
107
|
+
field: string;
|
|
108
|
+
} | {
|
|
109
|
+
step: string;
|
|
110
|
+
declared: string;
|
|
111
|
+
created: true;
|
|
112
|
+
} | {
|
|
113
|
+
step: string;
|
|
114
|
+
declared: string;
|
|
115
|
+
bound: string;
|
|
116
|
+
} | {
|
|
117
|
+
step: string;
|
|
118
|
+
custom: true;
|
|
119
|
+
op?: string;
|
|
120
|
+
called?: boolean;
|
|
121
|
+
};
|
|
122
|
+
export interface Scenario {
|
|
123
|
+
name: string;
|
|
124
|
+
/** The feature file, relative to the scenarios directory. */
|
|
125
|
+
file: string;
|
|
126
|
+
/** Its line in the file: its keyword's, or for an outline's row, the row's. */
|
|
127
|
+
line: number;
|
|
128
|
+
workflow: string;
|
|
129
|
+
/**
|
|
130
|
+
* The scenario's own lines of its feature file, for display: from its keyword line to the end
|
|
131
|
+
* of its last step (a step's doc string or table included, and an outline's examples), less
|
|
132
|
+
* the keyword line's indent. An outline's rows share their outline's.
|
|
133
|
+
*/
|
|
134
|
+
text: string;
|
|
135
|
+
/** Every step in order, for a list and for marking graph nodes. */
|
|
136
|
+
steps: ScenarioStep[];
|
|
137
|
+
given: Given[];
|
|
138
|
+
input: unknown;
|
|
139
|
+
decisions: Decision[];
|
|
140
|
+
/**
|
|
141
|
+
* The titles of the approvals the workflow's code asks for, where a title is a string literal
|
|
142
|
+
* (read from its outline), so `drive` can tell a decision for an approval still to come from
|
|
143
|
+
* one meant for whichever comes next.
|
|
144
|
+
*/
|
|
145
|
+
approvals: string[];
|
|
146
|
+
expect: Expectation[];
|
|
147
|
+
}
|
|
148
|
+
/** The result of one expectation against a run's ledger. */
|
|
149
|
+
export interface Check {
|
|
150
|
+
step: string;
|
|
151
|
+
ok: boolean;
|
|
152
|
+
detail?: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* What steps can name: the config's operations, workflows and resource types by id, the steps
|
|
156
|
+
* its connectors (and the company) ship, and where the feature files are.
|
|
157
|
+
*/
|
|
158
|
+
export type Scope = Pick<ResolvedConfig, "ops" | "workflows" | "scenarios" | "types" | "steps">;
|
|
159
|
+
type Fault = Extract<Seed, {
|
|
160
|
+
fault: unknown;
|
|
161
|
+
}>["fault"];
|
|
162
|
+
/** Where an operation's own test makes its calls: an operation's driver, live, replayed or a fake's, and the fake. */
|
|
163
|
+
export interface FeatureTarget {
|
|
164
|
+
driver: Driver;
|
|
165
|
+
/** The fake whose driver it is: a scenario's faults need one. */
|
|
166
|
+
fake?: Fake<any, any>;
|
|
167
|
+
}
|
|
168
|
+
/** What `loadScenarios` returns. */
|
|
169
|
+
export interface LoadedScenarios {
|
|
170
|
+
scenarios: Scenario[];
|
|
171
|
+
errors: {
|
|
172
|
+
file: string;
|
|
173
|
+
message: string;
|
|
174
|
+
}[];
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Every scenario in the `.feature` files under `scenarios` (a `file:` URL to a directory),
|
|
178
|
+
* compiled by Cucumber, with an error for each file that does not compile and each name used
|
|
179
|
+
* twice. No directory, or none given, is no scenarios. Rejects when an operation's phrase names
|
|
180
|
+
* a field it lacks. The files are compiled again only once one is added, removed or written
|
|
181
|
+
* (its name, `mtimeMs` or size changes): until then each call returns the same object, which
|
|
182
|
+
* callers must not change.
|
|
183
|
+
*/
|
|
184
|
+
export declare function loadScenarios(scope: Scope): Promise<LoadedScenarios>;
|
|
185
|
+
/**
|
|
186
|
+
* Checks a run's ledger records against the scenario, as its feature file reads now: Cucumber
|
|
187
|
+
* runs the scenario's `Then` steps, each judging the run on its own, and the rest of its steps
|
|
188
|
+
* do nothing. One check per expectation (`scenario.expect`), in order, a step that does not hold
|
|
189
|
+
* with why as its `detail`. Rejects when the scenario no longer compiles as it did (a step the
|
|
190
|
+
* file no longer matches, say): load the scenarios again first, as the app does.
|
|
191
|
+
*/
|
|
192
|
+
export declare function check(scope: Scope, scenario: Scenario, records: readonly LedgerRecord[]): Promise<Check[]>;
|
|
193
|
+
/**
|
|
194
|
+
* The scenarios of the `.feature` files under `dir` (a `file:` URL to a directory), in order,
|
|
195
|
+
* named as `loadScenarios` names them, from a dry run: what a test runner lists before it runs
|
|
196
|
+
* each (`testFeature`). Rejects, naming the file, for one Gherkin cannot parse.
|
|
197
|
+
*/
|
|
198
|
+
export declare function featureScenarios(scope: Scope, dir: URL): Promise<{
|
|
199
|
+
file: string;
|
|
200
|
+
line: number;
|
|
201
|
+
name: string;
|
|
202
|
+
tags: string[];
|
|
203
|
+
}[]>;
|
|
204
|
+
/**
|
|
205
|
+
* Runs the scenario at `line` of the feature file `file` (absolute) as an operation's own test,
|
|
206
|
+
* on the target: its `Given` steps seed through it, its `When` steps call its operations directly
|
|
207
|
+
* (no worker, no policy), and its `Then` steps check those calls. Rejects with its first step
|
|
208
|
+
* that did not pass, at `file:line`.
|
|
209
|
+
*/
|
|
210
|
+
export declare function testFeature(scope: Scope, file: string, line: number, target: FeatureTarget): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Decides the run's approvals as the scenario says until the run ends, and returns how it
|
|
213
|
+
* ended. Each pending approval takes the decision naming its title (or id), else the next one
|
|
214
|
+
* left that names no approval of the run (one it has asked for, or one its code names). Throws
|
|
215
|
+
* for an approval with no such decision, and `run_running` when the run has not ended within
|
|
216
|
+
* `timeoutMs` or the worker has not read a decision by then.
|
|
217
|
+
*/
|
|
218
|
+
export declare function drive(client: SanomaClient, runId: string, scenario: Scenario, { timeoutMs }?: {
|
|
219
|
+
timeoutMs?: number;
|
|
220
|
+
}): Promise<RunSummary>;
|
|
221
|
+
export {};
|