@staff0rd/assist 0.934.0 → 0.934.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.934.0",
9
+ version: "0.934.2",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -34043,10 +34043,10 @@ function getViolations(pattern2, options2 = {}, maxLines = DEFAULT_MAX_LINES2) {
34043
34043
  }
34044
34044
  const violations = [];
34045
34045
  for (const filePath of sourceFiles) {
34046
- const lineCount = countLines(filePath);
34046
+ const lineCount2 = countLines(filePath);
34047
34047
  const maxAllowed = ignoredFiles.get(filePath) ?? maxLines;
34048
- if (lineCount > maxAllowed) {
34049
- violations.push({ file: filePath, lines: lineCount });
34048
+ if (lineCount2 > maxAllowed) {
34049
+ violations.push({ file: filePath, lines: lineCount2 });
34050
34050
  }
34051
34051
  }
34052
34052
  return violations;
@@ -34901,8 +34901,8 @@ function ignore2(file) {
34901
34901
  process.exit(1);
34902
34902
  }
34903
34903
  const content = fs32.readFileSync(file, "utf8");
34904
- const lineCount = content.split("\n").length;
34905
- const maxLines = lineCount + 10;
34904
+ const lineCount2 = content.split("\n").length;
34905
+ const maxLines = lineCount2 + 10;
34906
34906
  const entry = `- file: ${file}
34907
34907
  maxLines: ${maxLines}
34908
34908
  `;
@@ -36563,33 +36563,73 @@ function capHighLevelPatches(files, criticalPaths) {
36563
36563
  return files.map((file) => byPath.get(file.path) ?? file);
36564
36564
  }
36565
36565
 
36566
- // src/commands/review/highLevel/capHighLevelTestSources.ts
36566
+ // src/commands/review/highLevel/testChangeExcerpts.ts
36567
+ var CONTEXT_LINES = 3;
36568
+ function testChangeExcerpts(source, line, changedLines2) {
36569
+ const lines2 = source.split("\n");
36570
+ const windows = [];
36571
+ for (const changed of [...changedLines2].sort((a, b) => a - b)) {
36572
+ const start2 = Math.max(0, changed - line - CONTEXT_LINES);
36573
+ const end = Math.min(lines2.length - 1, changed - line + CONTEXT_LINES);
36574
+ const last = windows.at(-1);
36575
+ if (last && start2 <= last.end + 1) last.end = Math.max(last.end, end);
36576
+ else windows.push({ start: start2, end });
36577
+ }
36578
+ return windows.map(({ start: start2, end }) => ({
36579
+ line: line + start2,
36580
+ source: lines2.slice(start2, end + 1).join("\n")
36581
+ }));
36582
+ }
36583
+
36584
+ // src/commands/review/highLevel/shownForm.ts
36567
36585
  var MAX_TEST_SOURCE_LINES = 200;
36586
+ function shownForm(test) {
36587
+ const { source, changedLines: changedLines2, ...rest } = test;
36588
+ if (source === void 0) return void 0;
36589
+ const lines2 = lineCount(source);
36590
+ if (lines2 <= MAX_TEST_SOURCE_LINES)
36591
+ return { lines: lines2, shown: { ...rest, source } };
36592
+ if (!changedLines2) return void 0;
36593
+ const excerpts = testChangeExcerpts(source, test.line, changedLines2);
36594
+ const excerptLines = excerpts.reduce(
36595
+ (sum3, excerpt2) => sum3 + lineCount(excerpt2.source),
36596
+ 0
36597
+ );
36598
+ return excerptLines <= MAX_TEST_SOURCE_LINES ? { lines: excerptLines, shown: { ...rest, excerpts } } : void 0;
36599
+ }
36600
+ function lineCount(text17) {
36601
+ return text17.split("\n").length;
36602
+ }
36603
+
36604
+ // src/commands/review/highLevel/capHighLevelTestSources.ts
36568
36605
  var MAX_TOTAL_SOURCE_LINES = 5e3;
36569
36606
  function collectCases(nodes) {
36570
36607
  return nodes.flatMap(
36571
36608
  (node) => node.kind === "it" ? [node] : collectCases(node.children)
36572
36609
  );
36573
36610
  }
36574
- function shippedCases(files) {
36575
- const sized = files.flatMap((file) => collectCases(file.tests)).flatMap(
36576
- (test) => test.source === void 0 ? [] : [{ test, lines: test.source.split("\n").length }]
36577
- ).filter(({ lines: lines2 }) => lines2 <= MAX_TEST_SOURCE_LINES).sort((a, b) => a.lines - b.lines);
36578
- const shipped = /* @__PURE__ */ new Set();
36611
+ function shippedForms(files) {
36612
+ const sized = files.flatMap((file) => collectCases(file.tests)).flatMap((test) => {
36613
+ const form = shownForm(test);
36614
+ return form ? [{ test, form }] : [];
36615
+ }).sort((a, b) => a.form.lines - b.form.lines);
36616
+ const shipped = /* @__PURE__ */ new Map();
36579
36617
  let remaining = MAX_TOTAL_SOURCE_LINES;
36580
- for (const { test, lines: lines2 } of sized) {
36581
- if (lines2 > remaining) break;
36582
- remaining -= lines2;
36583
- shipped.add(test);
36618
+ for (const { test, form } of sized) {
36619
+ if (form.lines > remaining) break;
36620
+ remaining -= form.lines;
36621
+ shipped.set(test, form);
36584
36622
  }
36585
36623
  return shipped;
36586
36624
  }
36587
36625
  function capHighLevelTestSources(files) {
36588
- const shipped = shippedCases(files);
36626
+ const shipped = shippedForms(files);
36589
36627
  const capCase = (test) => {
36590
- if (test.source === void 0 || shipped.has(test)) return test;
36591
- const { source, ...rest } = test;
36592
- return source.split("\n").length > MAX_TEST_SOURCE_LINES ? { ...rest, truncated: true } : { ...rest, overBudget: true };
36628
+ const form = shipped.get(test);
36629
+ if (form) return form.shown;
36630
+ const { source, changedLines: _changedLines, ...rest } = test;
36631
+ if (source === void 0) return rest;
36632
+ return shownForm(test) ? { ...rest, overBudget: true } : { ...rest, truncated: true };
36593
36633
  };
36594
36634
  const capNode = (node) => node.kind === "it" ? capCase(node) : { ...node, children: node.children.map(capNode) };
36595
36635
  return files.map((file) => ({ ...file, tests: file.tests.map(capNode) }));
@@ -36645,28 +36685,34 @@ function dedentedSource(call) {
36645
36685
 
36646
36686
  // src/commands/review/highLevel/visitCase.ts
36647
36687
  function visitCase(call, context) {
36648
- if (!context.changed) return [toCase(call, context, void 0)];
36649
- const count10 = changedLines(call, context.changed);
36650
- if (count10 === 0) return [];
36651
- const lines2 = call.getEndLineNumber() - call.getStartLineNumber() + 1;
36652
- return [toCase(call, context, count10 === lines2 ? "added" : "modified")];
36688
+ if (!context.changed) return [toCase(call, context)];
36689
+ const lines2 = changedLines(call, context.changed);
36690
+ if (lines2.length === 0) return [];
36691
+ const total2 = call.getEndLineNumber() - call.getStartLineNumber() + 1;
36692
+ return [
36693
+ toCase(
36694
+ call,
36695
+ context,
36696
+ lines2.length === total2 ? { change: "added" } : { change: "modified", changedLines: lines2 }
36697
+ )
36698
+ ];
36653
36699
  }
36654
- function toCase(call, context, change) {
36700
+ function toCase(call, context, change = {}) {
36655
36701
  const line = call.getStartLineNumber();
36656
36702
  return {
36657
36703
  kind: "it",
36658
36704
  id: `${context.path}:${line}`,
36659
36705
  name: testName(call),
36660
36706
  line,
36661
- ...change ? { change } : {},
36707
+ ...change,
36662
36708
  source: dedentedSource(call)
36663
36709
  };
36664
36710
  }
36665
36711
  function changedLines(call, changed) {
36666
- let count10 = 0;
36712
+ const lines2 = [];
36667
36713
  for (let line = call.getStartLineNumber(); line <= call.getEndLineNumber(); line++)
36668
- if (changed.has(line)) count10++;
36669
- return count10;
36714
+ if (changed.has(line)) lines2.push(line);
36715
+ return lines2;
36670
36716
  }
36671
36717
 
36672
36718
  // src/commands/review/highLevel/extractTestHierarchy.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.934.0",
3
+ "version": "0.934.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {