unitbob 0.7.7 → 0.7.12

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.
@@ -24,6 +24,65 @@ export function reportedFailures(runner, report) {
24
24
  return null;
25
25
  return extract(runner, report);
26
26
  }
27
+ // Spec 52-4, AC 1.10. The same parse, read for a third question: how many of
28
+ // a feature's scenarios passed and how many did not. `put-tests` decides from
29
+ // it which proof to attach — all red is the red run, all green with a review
30
+ // is the review, anything else is no proof — and whether a review may be sent
31
+ // at all. The number reaches a sentence on this machine and the choice of a
32
+ // field; the server checks whatever proof it is sent against the report
33
+ // itself. Only the two behavioral shapes have scenarios to count; a report
34
+ // that cannot be read is no tally, never a green one.
35
+ export function scenarioTally(runner, report) {
36
+ if (!report.trim())
37
+ return null;
38
+ const outcomes = scenarioOutcomes(runner, report);
39
+ if (outcomes === null)
40
+ return null;
41
+ const failed = outcomes.filter((passed) => !passed).length;
42
+ return { passed: outcomes.length - failed, failed };
43
+ }
44
+ // One entry per scenario, true when it passed. Cucumber emits one
45
+ // `testCaseStarted` per attempt when a scenario is retried, so the rows are
46
+ // keyed by the test case and the last attempt is the one that counts — the
47
+ // one the run ended on.
48
+ function scenarioOutcomes(runner, report) {
49
+ switch (runner) {
50
+ case 'cucumber':
51
+ case 'cucumber-js': {
52
+ const envelopes = [];
53
+ for (const line of report.split('\n')) {
54
+ if (!line.trim())
55
+ continue;
56
+ const parsed = parseObject(line);
57
+ if (!parsed)
58
+ return null;
59
+ envelopes.push(parsed);
60
+ }
61
+ const failedRuns = new Set();
62
+ for (const envelope of envelopes) {
63
+ const finished = envelope.testStepFinished;
64
+ const status = text(finished?.testStepResult?.status);
65
+ if (finished && status !== 'PASSED' && status !== 'SKIPPED')
66
+ failedRuns.add(text(finished.testCaseStartedId));
67
+ }
68
+ const lastAttempt = new Map();
69
+ for (const envelope of envelopes) {
70
+ const started = envelope.testCaseStarted;
71
+ if (started)
72
+ lastAttempt.set(text(started.testCaseId), text(started.id));
73
+ }
74
+ return [...lastAttempt.values()].map((startedId) => !failedRuns.has(startedId));
75
+ }
76
+ case 'pytest-bdd': {
77
+ const data = parseObject(report);
78
+ if (!Array.isArray(data?.scenarios))
79
+ return null;
80
+ return rows(data.scenarios).map((scenario) => text(scenario.status) === 'passed');
81
+ }
82
+ default:
83
+ return null;
84
+ }
85
+ }
27
86
  // One hash for one set. Same set, same hash, on any machine and in any order.
28
87
  export function digestOf(failures) {
29
88
  return createHash('sha256').update(JSON.stringify(failures)).digest('hex');
@@ -0,0 +1,20 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ // The revision a connector-made run was taken at, for the server's record:
3
+ // `git rev-parse HEAD`, with `-dirty` when the tree has changes, or a word
4
+ // when there is no git to ask. Read by the known-defect probe (the review)
5
+ // and by the proof of red of a feature's checks (spec 52-3), from one place.
6
+ export function gitRevision(projectRoot) {
7
+ try {
8
+ const options = {
9
+ cwd: projectRoot,
10
+ encoding: 'utf8',
11
+ stdio: ['ignore', 'pipe', 'pipe'],
12
+ };
13
+ const head = execFileSync('git', ['rev-parse', 'HEAD'], options).trim();
14
+ const dirty = execFileSync('git', ['status', '--porcelain'], options).trim();
15
+ return dirty ? `${head}-dirty` : head;
16
+ }
17
+ catch {
18
+ return 'working-tree';
19
+ }
20
+ }
@@ -24,7 +24,9 @@ export function withInstalledRunnerVersion(envelope, runner, projectRoot) {
24
24
  const BEHAVIORAL_DIR = '.unitbob/behavioral';
25
25
  // Matches the server's own PINNED_VERSION: a digit, then version characters.
26
26
  const PINNED_VERSION = /^[0-9][0-9A-Za-z.\-+]*$/;
27
- function installedRunnerVersion(runner, projectRoot) {
27
+ // Exported for a feature's checks (spec 52-3), which take the runner from the
28
+ // main suite rather than from a selection and still owe the server its version.
29
+ export function installedRunnerVersion(runner, projectRoot) {
28
30
  const root = join(projectRoot, BEHAVIORAL_DIR);
29
31
  const found = readInstalledVersion(runner, root);
30
32
  return found && PINNED_VERSION.test(found) ? found : null;
@@ -0,0 +1,13 @@
1
+ // The end of what a run printed, stderr first: enough to see why a runner
2
+ // died, not the whole log. One place for the three verbs that print it
3
+ // (`check`, `run-local`, `put-tests`); `run-local` asks for more because the
4
+ // person is reading it in a loop, `check` files it into a suite error.
5
+ export function outputTail(result, limit) {
6
+ const bits = [];
7
+ if (result.stderr.trim())
8
+ bits.push(result.stderr.trim());
9
+ if (result.stdout.trim())
10
+ bits.push(result.stdout.trim());
11
+ const joined = bits.join('\n');
12
+ return joined.length > limit ? joined.slice(-limit) : joined;
13
+ }
@@ -7,6 +7,13 @@
7
7
  //
8
8
  // It only records — it never reconciles markers or aggregates capabilities. It
9
9
  // is connector-owned and never part of the LLM-generated step definitions.
10
+ //
11
+ // A step with no definition is recorded too (spec 52-3, AC 3.7): pytest-bdd
12
+ // calls `pytest_bdd_step_func_lookup_error` for it and never `after_step`, so
13
+ // without this hook the scenario went into the report as `passed` with no
14
+ // steps — and a feature's checks, which have to prove they are red, could
15
+ // have passed that proof on wiring nobody wrote. The server's parser refuses
16
+ // an `undefined` step as a broken suite, which is the honest answer.
10
17
  export const PYTEST_BDD_PLUGIN = `# Written by the unitbob connector — do not edit.
11
18
  import json
12
19
  import os
@@ -62,6 +69,14 @@ def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func
62
69
  _record_step(scenario, step, "failed")
63
70
 
64
71
 
72
+ def pytest_bdd_step_func_lookup_error(request, feature, scenario, step, exception):
73
+ entry = _UNITBOB_CURRENT.get(id(scenario))
74
+ if entry is not None:
75
+ entry["status"] = "failed"
76
+ entry["failure"] = "{}: {}".format(type(exception).__name__, exception)
77
+ _record_step(scenario, step, "undefined")
78
+
79
+
65
80
  def pytest_bdd_after_scenario(request, feature, scenario):
66
81
  entry = _UNITBOB_CURRENT.pop(id(scenario), None)
67
82
  if entry is not None:
@@ -5,21 +5,40 @@ import { Wire } from "../wire.js";
5
5
  // The server composes the whole prompt; the connector prints its plain-language
6
6
  // `message` and the copy-ready `prompt`. A 422 (not current / not failing /
7
7
  // unknown intent) surfaces via WireError; nothing is fabricated.
8
+ //
9
+ // `feature:<id>` stands in for the digest (spec 52-4, AC 1.3): a feature's
10
+ // checks are not on the map to copy one from, so the id is resolved to
11
+ // the digest of the feature's current checks through the same index `check`
12
+ // runs from. The server words the brief itself, and answers 422 to `accept` —
13
+ // a feature's scenarios change through the talk, not through an accept.
8
14
  export async function contractPrompt(config, args = [], deps) {
9
- const suiteDigest = (args[0] ?? '').trim();
15
+ const selector = (args[0] ?? '').trim();
10
16
  const testId = (args[1] ?? '').trim();
11
17
  const intent = (args[2] ?? 'fix').trim();
12
- if (!suiteDigest || !testId) {
13
- throw new Error('Usage: unitbob contract-prompt <suite_digest> <test_id> [fix|accept]');
18
+ if (!selector || !testId) {
19
+ throw new Error('Usage: unitbob contract-prompt <suite_digest>|feature:<id> <test_id> [fix|accept]');
14
20
  }
15
21
  if (intent !== 'fix' && intent !== 'accept') {
16
22
  throw new Error(`intent must be "fix" or "accept" (got "${intent}").`);
17
23
  }
24
+ const wire = new Wire(config);
18
25
  const d = {
19
- getContractPrompt: (digest, id, action) => new Wire(config).getContractPrompt(digest, id, action),
26
+ getContractPrompt: (digest, id, action) => wire.getContractPrompt(digest, id, action),
27
+ getSuiteIndex: () => wire.getSuiteIndex(),
20
28
  stdout: process.stdout,
21
29
  ...deps,
22
30
  };
31
+ const suiteDigest = selector.startsWith(FEATURE_SELECTOR) ? await featureDigest(d, selector.slice(FEATURE_SELECTOR.length)) : selector;
23
32
  const packet = await d.getContractPrompt(suiteDigest, testId, intent);
24
33
  d.stdout.write(`${packet.message}\n\n${packet.prompt}\n`);
25
34
  }
35
+ const FEATURE_SELECTOR = 'feature:';
36
+ // The digest of the feature's current checks. Only a feature being built has
37
+ // them in the index: before the checks are written there is nothing to act on,
38
+ // and after Finish they are part of the main suite, on the map like the rest.
39
+ async function featureDigest(d, id) {
40
+ const item = (await d.getSuiteIndex()).feature_suites.find((entry) => String(entry.feature_id) === id);
41
+ if (!item)
42
+ throw new Error(`No feature ${id} has checks to act on — it is not being built, or it is finished.`);
43
+ return item.suite_digest;
44
+ }
@@ -0,0 +1,49 @@
1
+ import { requestPath, writeFeatureStartRequest } from "../files/featureStart.js";
2
+ import { Wire } from "../wire.js";
3
+ // Fetch the recipe and the behavioral assignment — the product capabilities of
4
+ // the current map, with what each promises and where in the checkout it lives —
5
+ // and write the host's task to `.unitbob/feature-start/request.json` (spec
6
+ // 52-1). One request for the list, the same one `suite-prepare` makes; today's
7
+ // check statuses are not asked for, because they belong on the feature's page
8
+ // and not in the judgement of what the work may touch. No model is called,
9
+ // no source is read, nothing is uploaded. A 409 (no current map) surfaces as a
10
+ // WireError with the server's guidance and nothing is written.
11
+ export async function featurePrepare(config, _args = [], deps) {
12
+ const wire = new Wire(config);
13
+ const d = {
14
+ getRecipe: (name) => wire.getRecipe(name),
15
+ getSuitePacketsBatch: () => wire.getSuitePacketsBatch(),
16
+ stdout: process.stdout,
17
+ ...deps,
18
+ };
19
+ const [recipe, packets] = await Promise.all([d.getRecipe('feature_intent'), d.getSuitePacketsBatch()]);
20
+ const behavioral = packets.find((packet) => packet.suite_kind === 'behavioral');
21
+ if (!behavioral) {
22
+ throw new Error('The Unitbob server sent no behavioral assignment with the suite packets — it is older than this connector. ' +
23
+ 'Update the server (or the connector) so the two agree, then retry.');
24
+ }
25
+ writeFeatureStartRequest(config.projectRoot, recipe, capabilitiesOf(behavioral));
26
+ d.stdout.write(`Feature request written to ${requestPath(config.projectRoot)}\n`);
27
+ }
28
+ // The six fields the recipe names, in the shape it names them. The contract
29
+ // identity (`contract_key`, `case_marker`) rides in the assignment for the
30
+ // suite recipe and is not copied: the host is naming what may be touched, not
31
+ // writing tests.
32
+ function capabilitiesOf(packet) {
33
+ const assignment = (packet.assignment ?? {});
34
+ const list = Array.isArray(assignment.capabilities) ? assignment.capabilities : [];
35
+ return list.map((entry) => {
36
+ const item = (typeof entry === 'object' && entry !== null ? entry : {});
37
+ return {
38
+ capability_id: String(item.capability_id ?? ''),
39
+ title: String(item.title ?? ''),
40
+ description: String(item.description ?? ''),
41
+ surfaces: strings(item.surfaces),
42
+ tables: strings(item.tables),
43
+ externals: strings(item.externals),
44
+ };
45
+ });
46
+ }
47
+ function strings(value) {
48
+ return Array.isArray(value) ? value.map((one) => String(one)) : [];
49
+ }
@@ -0,0 +1,39 @@
1
+ import { knowledgeRequestPath, parseFeatureId, writeKnowledgeRequest } from "../files/features.js";
2
+ import { Wire } from "../wire.js";
3
+ // The statuses a feature can be talked through in: not yet talked through,
4
+ // talked through and open to a second talk (spec 52-2, AC 2.1), or its checks
5
+ // written — a talk then withdraws them, out loud (spec 52-3, AC 2.9).
6
+ const TALKABLE = new Set(['intent', 'knowledge', 'red']);
7
+ // Two forms (spec 52-2, AC 2.1). Without an id, the list: one line per feature
8
+ // the talk can start on, so the host finds the one the person means by its
9
+ // words — and the server's own sentence when there is none; the connector
10
+ // words no state of its own. With an id, the host's task: the recipe and the
11
+ // packet the server built, written to `.unitbob/features/<id>/request.json`
12
+ // next to where `knowledge.md` will go. No model is called, nothing is
13
+ // uploaded.
14
+ export async function knowledgePrepare(config, args = [], deps) {
15
+ const wire = new Wire(config);
16
+ const d = {
17
+ listFeatures: () => wire.listFeatures(),
18
+ getRecipe: (name) => wire.getRecipe(name),
19
+ getKnowledgePacket: (id) => wire.getKnowledgePacket(id),
20
+ stdout: process.stdout,
21
+ ...deps,
22
+ };
23
+ if (args.length === 0) {
24
+ const list = await d.listFeatures();
25
+ const talkable = list.features.filter((feature) => TALKABLE.has(feature.status));
26
+ if (talkable.length === 0) {
27
+ d.stdout.write(`${list.empty_text}\n`);
28
+ return;
29
+ }
30
+ for (const feature of talkable) {
31
+ d.stdout.write(`${feature.feature_id} ${feature.title} (${feature.status})\n`);
32
+ }
33
+ return;
34
+ }
35
+ const featureId = parseFeatureId(args[0], 'knowledge-prepare');
36
+ const [recipe, packet] = await Promise.all([d.getRecipe('feature_grill'), d.getKnowledgePacket(featureId)]);
37
+ writeKnowledgeRequest(config.projectRoot, featureId, recipe, packet);
38
+ d.stdout.write(`Knowledge request written to ${knowledgeRequestPath(config.projectRoot, featureId)}\n`);
39
+ }
@@ -1,7 +1,7 @@
1
1
  import { ensureUnitbobIgnored, ignoreExclusions, requireGraphify, runGraphifyExtractKeyless } from "../proc.js";
2
2
  import { readFreshGraph, writeMapBuildRequest } from "../files/mapBuild.js";
3
3
  import { describeRouteInventory, extractRouteInventory, } from "../surfaces/routeInventory.js";
4
- import { Wire } from "../wire.js";
4
+ import { Wire, WireError } from "../wire.js";
5
5
  export async function mapPrepare(config, _args = [], deps) {
6
6
  const wire = new Wire(config);
7
7
  const actual = {
@@ -10,7 +10,9 @@ export async function mapPrepare(config, _args = [], deps) {
10
10
  runGraphifyExtractKeyless,
11
11
  extractRouteInventory,
12
12
  getRecipe: (name) => wire.getRecipe(name),
13
+ listFeatures: () => wire.listFeatures(),
13
14
  stdout: process.stdout,
15
+ stderr: process.stderr,
14
16
  ...deps,
15
17
  };
16
18
  actual.ensureUnitbobIgnored(config.projectRoot);
@@ -44,18 +46,19 @@ export async function mapPrepare(config, _args = [], deps) {
44
46
  // us there reads as a hang.
45
47
  actual.stdout.write('Asking this project for the addresses it declares (this boots the application)…\n');
46
48
  const inventory = await actual.extractRouteInventory(config.projectRoot);
47
- const [decompose, relate, extractSurfaces, decomposeSurfaces] = await Promise.all([
49
+ const [decompose, relate, extractSurfaces, decomposeSurfaces, existing] = await Promise.all([
48
50
  actual.getRecipe('decompose'),
49
51
  actual.getRecipe('relate'),
50
52
  actual.getRecipe('extract_surfaces'),
51
53
  actual.getRecipe('decompose_surfaces'),
54
+ existingCapabilities(actual),
52
55
  ]);
53
56
  const packet = writeMapBuildRequest(config.projectRoot, {
54
57
  decompose,
55
58
  relate,
56
59
  extract_surfaces: extractSurfaces,
57
60
  decompose_surfaces: decomposeSurfaces,
58
- }, inventory.status === 'written' ? inventory.path : undefined);
61
+ }, inventory.status === 'written' ? inventory.path : undefined, existing);
59
62
  actual.stdout.write(`Map build request written to ${packet.project_root}/.unitbob/map-build/request.json\n`);
60
63
  actual.stdout.write(`${describeRouteInventory(inventory)}\n`);
61
64
  actual.stdout.write(`Next: build BOTH lenses following the recipes in that request — the decompose map at ` +
@@ -63,3 +66,26 @@ export async function mapPrepare(config, _args = [], deps) {
63
66
  `${packet.surface_output_path} (recipes.extract_surfaces → ${packet.surfaces_path}, then ` +
64
67
  'recipes.decompose_surfaces) — then run `unitbob put-map-build`.\n');
65
68
  }
69
+ // The capabilities finished features added to the map (spec 52-4, AC 5.1):
70
+ // by id, title and the intent as said — no addresses, the recipe matches by
71
+ // meaning. Only finished features: an open one is not on the map yet. A
72
+ // server older than the fields sends rows without a capability id, and one
73
+ // older than the route answers 404; both read as none, quietly, and the
74
+ // recipe skips its paragraph (AC 7.3). Any other failure of the list is not
75
+ // a reason to stop a map build either — but it is said, on stderr, because a
76
+ // map built without the finished features' ids is one that may redraw them.
77
+ async function existingCapabilities(d) {
78
+ let features;
79
+ try {
80
+ features = (await d.listFeatures()).features;
81
+ }
82
+ catch (err) {
83
+ if (!(err instanceof WireError && err.status === 404)) {
84
+ d.stderr.write(`Could not list finished features — the map is built without them: ${err.message}\n`);
85
+ }
86
+ return [];
87
+ }
88
+ return features
89
+ .filter((feature) => feature.status === 'done' && typeof feature.capability_id === 'string')
90
+ .map((feature) => ({ id: feature.capability_id, title: feature.title, description: feature.intent ?? '' }));
91
+ }
@@ -0,0 +1,21 @@
1
+ import { readFeatureAnswer } from "../files/featureStart.js";
2
+ import { enterUrl } from "../links.js";
3
+ import { Wire } from "../wire.js";
4
+ // Read the host's answer and record the feature (spec 52-1). The server checks
5
+ // every id against the current map and words the sentence; this prints it and
6
+ // the link to the feature's page through the exchanger, like every link a
7
+ // person gets from the terminal (spec 33). A 422 — an id not on the map — is
8
+ // let through as a WireError with both id lists in its text, so the host
9
+ // corrects its file and runs this again. Nothing is created locally: the
10
+ // feature's folder, its knowledge file and its tests belong to later specs.
11
+ export async function putFeature(config, _args = [], deps) {
12
+ const d = {
13
+ postFeature: (payload) => new Wire(config).postFeature(payload),
14
+ stdout: process.stdout,
15
+ ...deps,
16
+ };
17
+ const answer = readFeatureAnswer(config.projectRoot);
18
+ const recorded = await d.postFeature(answer);
19
+ d.stdout.write(`${recorded.message}\n`);
20
+ d.stdout.write(`${enterUrl(config, recorded.url)}\n`);
21
+ }
@@ -0,0 +1,21 @@
1
+ import { parseFeatureId, readKnowledge } from "../files/features.js";
2
+ import { enterUrl } from "../links.js";
3
+ import { Wire } from "../wire.js";
4
+ // Send `knowledge.md` as text (spec 52-2, AC 2.2) and print the server's
5
+ // sentence and the link to the feature's page through the exchanger, like
6
+ // every link a person gets from the terminal (spec 33). The shape is checked
7
+ // on the server only (Non-Goals); a 422 comes back through the wire as a
8
+ // WireError whose text already holds one line per problem, both sides, and
9
+ // this lets it through so the host fixes the file and runs this again.
10
+ export async function putKnowledge(config, args = [], deps) {
11
+ const d = {
12
+ putKnowledge: (id, knowledge) => new Wire(config).putKnowledge(id, knowledge),
13
+ stdout: process.stdout,
14
+ ...deps,
15
+ };
16
+ const featureId = parseFeatureId(args[0], 'put-knowledge');
17
+ const text = readKnowledge(config.projectRoot, featureId);
18
+ const recorded = await d.putKnowledge(featureId, text);
19
+ d.stdout.write(`${recorded.message}\n`);
20
+ d.stdout.write(`${enterUrl(config, recorded.url)}\n`);
21
+ }
@@ -0,0 +1,133 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { knowledgePath, parseFeatureId, readKnowledge, readTestsOutput, readTestsRequest, readTestsReviewOutput, testsReviewOutputPath, } from "../files/features.js";
3
+ import { suiteCandidateDigest } from "../files/suiteBuild.js";
4
+ import { enterUrl } from "../links.js";
5
+ import { runBddSuite } from "../runner/bdd.js";
6
+ import { boundReport } from "../runner/boundReport.js";
7
+ import { scenarioTally } from "../runner/failureDigest.js";
8
+ import { gitRevision } from "../runner/gitRevision.js";
9
+ import { placeAdvice } from "../runner/placeAdvice.js";
10
+ import { placeProblem } from "../runner/place.js";
11
+ import { runnerEnvironmentPlaceProblem } from "../runner/placeEnvironment.js";
12
+ import { outputTail } from "../runner/outputTail.js";
13
+ import { Wire } from "../wire.js";
14
+ const OUTPUT_TAIL_CHARS = 2000;
15
+ // The digest of `knowledge.md` on disk against the one the request was written
16
+ // from — both named when they differ, so the reader sees which side moved.
17
+ export function assertKnowledgeUnchanged(projectRoot, featureId, expected) {
18
+ const got = createHash('sha256').update(readKnowledge(projectRoot, featureId)).digest('hex');
19
+ if (got === expected)
20
+ return;
21
+ throw new Error(`${knowledgePath(projectRoot, featureId)}: knowledge.md on disk differs from what the server has — ` +
22
+ `run put-knowledge first, or restore the file, then run this again.\nexpected: ${expected}\n got: ${got}`);
23
+ }
24
+ // `put-tests <feature_id>` (spec 52-3, AC 3.5). The answer is read with its
25
+ // files from disk; the candidate digest is the one the review uses; then the
26
+ // connector runs the feature's tag itself — a report the host already has may
27
+ // be from earlier and over other files, and the proof has to be over these
28
+ // bytes. A runner that could not start or produced no report sends nothing:
29
+ // what it said is printed, and the exit code is non-zero. A 409 or 422 comes
30
+ // back as a WireError already worded by the server, one line per side, and is
31
+ // let through as it is.
32
+ //
33
+ // What the run proves decides what travels with it (spec 52-4, AC 1.10). All
34
+ // red: the run itself as `red_run`, revision and all, the way the known-defect
35
+ // probe sends its own. All green with the reviewer's file beside the answer:
36
+ // that file as `bdd_quality_review`, bound to this candidate. Anything else:
37
+ // no proof — the harness was saved mid-build. A review over a run that is not
38
+ // all green is not sent at all; a review of an older candidate is ignored out
39
+ // loud. And once the server has taken the version, the same run is filed
40
+ // under its digest, so the feature's page shows "N of M checks pass" on it at
41
+ // once rather than on the version before.
42
+ export async function putTests(config, args = [], deps) {
43
+ const wire = new Wire(config);
44
+ const d = {
45
+ runBehavioral: runBddSuite,
46
+ gitRevision,
47
+ putFeatureSuite: (id, upload) => wire.putFeatureSuite(id, upload),
48
+ postRunsBatch: (runs) => wire.postRunsBatch(runs),
49
+ stdout: process.stdout,
50
+ ...deps,
51
+ };
52
+ const featureId = parseFeatureId(args[0], 'put-tests');
53
+ const request = readTestsRequest(config.projectRoot, featureId);
54
+ const output = readTestsOutput(config.projectRoot, featureId);
55
+ // The same check `tests-prepare` made, made again here: the file may have
56
+ // been edited in between, and the checks are sealed to the text the server
57
+ // has, not to the text on disk (spec 52-3, edge cases).
58
+ assertKnowledgeUnchanged(config.projectRoot, featureId, request.knowledge_digest);
59
+ const unusable = placeProblem(config.projectRoot) ?? runnerEnvironmentPlaceProblem(config.projectRoot);
60
+ if (unusable)
61
+ throw new Error(unusable);
62
+ // The review file, before the run: one the connector cannot read is a
63
+ // stop, said in one line, and a run before it would be a run for nothing.
64
+ const candidateDigest = suiteCandidateDigest({
65
+ suite_kind: 'behavioral', suite_file: output.suite_file, runner_manifest: output.runner_manifest,
66
+ });
67
+ let review;
68
+ try {
69
+ review = readTestsReviewOutput(config.projectRoot, featureId);
70
+ }
71
+ catch (err) {
72
+ d.stdout.write(`${err.message}\n`);
73
+ d.stdout.write('Nothing was sent.\n');
74
+ return 1;
75
+ }
76
+ if (review && review.candidate_digest !== candidateDigest) {
77
+ d.stdout.write(`${testsReviewOutputPath(config.projectRoot, featureId)} is for an older candidate — ignored.\n`);
78
+ review = null;
79
+ }
80
+ let result;
81
+ try {
82
+ result = await d.runBehavioral(config.projectRoot, request.runner, request.feature_path, { only: request.feature_tag });
83
+ }
84
+ catch (err) {
85
+ const advice = placeAdvice(config.projectRoot);
86
+ d.stdout.write(`The runner could not start: ${err.message}\n${advice ? `\n${advice}\n` : ''}`);
87
+ d.stdout.write('Nothing was sent.\n');
88
+ return 1;
89
+ }
90
+ const report = boundReport(request.runner, result);
91
+ if (report === null) {
92
+ d.stdout.write(`The run produced no machine-readable report at ${result.resultPath} (exit code ${result.code}) — ` +
93
+ 'it died before the first scenario rather than failing them.\n');
94
+ const tail = outputTail(result, OUTPUT_TAIL_CHARS);
95
+ if (tail)
96
+ d.stdout.write(`${tail}\n`);
97
+ d.stdout.write('Nothing was sent.\n');
98
+ return 1;
99
+ }
100
+ const tally = scenarioTally(request.runner, result.report);
101
+ const allRed = tally !== null && tally.passed === 0 && tally.failed > 0;
102
+ const allGreen = tally !== null && tally.failed === 0 && tally.passed > 0;
103
+ if (review && !allGreen) {
104
+ d.stdout.write(`Review the checks when they all pass — ${stillFailing(tally)}.\n`);
105
+ return 1;
106
+ }
107
+ const proof = review
108
+ ? { bdd_quality_review: { ...review.bdd_quality_review, candidate_digest: candidateDigest } }
109
+ : allRed
110
+ ? { red_run: { candidate_digest: candidateDigest, revision: d.gitRevision(config.projectRoot), run_result: report } }
111
+ : {};
112
+ const recorded = await d.putFeatureSuite(featureId, {
113
+ suite_file: output.suite_file,
114
+ runner_manifest: output.runner_manifest,
115
+ test_metadata: { ...output.test_metadata, ...proof },
116
+ knowledge_digest: request.knowledge_digest,
117
+ });
118
+ // Said before the run is filed: the upload is done whatever happens next,
119
+ // and a filing that fails leaves the run to the next `check`.
120
+ d.stdout.write(`${recorded.message}\n`);
121
+ const { results } = await d.postRunsBatch([{ suite_digest: recorded.suite_digest, run_result: report }]);
122
+ for (const item of results)
123
+ d.stdout.write(`${item.summary}\n`);
124
+ d.stdout.write(`${enterUrl(config, recorded.url)}\n`);
125
+ return 0;
126
+ }
127
+ // "2 of 5 still fail" — or, for a report the connector could not count, only
128
+ // that it could not.
129
+ function stillFailing(tally) {
130
+ if (tally === null)
131
+ return 'the run’s report could not be read scenario by scenario';
132
+ return `${tally.failed} of ${tally.passed + tally.failed} still fail`;
133
+ }