Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7072ea5

Browse files
feat: completely overhoal workflows (#212)
1 parent 5b5f655 commit 7072ea5

File tree

6 files changed

+330
-112
lines changed

6 files changed

+330
-112
lines changed

‎tools/javascript/lib/JavaScriptLauncher.ts‎

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import { StorageManager } from "@syntest/storage";
8787

8888
import { TestCommandOptions } from "./commands/test";
8989
import { DeDuplicator } from "./workflows/DeDuplicator";
90-
import { addMetaComments } from "./workflows/MetaComment";
90+
import { MetaCommenter } from "./workflows/MetaCommenter";
9191
import { TestSplitting } from "./workflows/TestSplitter";
9292

9393
export type JavaScriptArguments = ArgumentsObject & TestCommandOptions;
@@ -440,7 +440,6 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
440440
this.userInterface.printHeader("Postprocessing started");
441441
JavaScriptLauncher.LOGGER.info("Postprocessing started");
442442
const start = Date.now();
443-
const testSplitter = new TestSplitting(this.runner);
444443
const objectives = new Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>(
445444
[...this.archives.entries()].map(([target, archive]) => [
446445
target,
@@ -455,17 +454,21 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
455454
);
456455

457456
if (this.arguments_.testSplitting) {
457+
const testSplitter = new TestSplitting(this.userInterface, this.runner);
458+
458459
const start = Date.now();
459-
const before = [...finalEncodings.values()]
460-
.map((x) => x.length)
461-
.reduce((p, c) => p + c);
460+
const before = [...finalEncodings.values()].reduce(
461+
(p, c) => p + c.length,
462+
0
463+
);
462464
JavaScriptLauncher.LOGGER.info("Splitting started");
463-
finalEncodings = await testSplitter.testSplitting(finalEncodings);
465+
finalEncodings = await testSplitter.execute(finalEncodings);
464466

465467
const timeInMs = (Date.now() - start) / 1000;
466-
const after = [...finalEncodings.values()]
467-
.map((x) => x.length)
468-
.reduce((p, c) => p + c);
468+
const after = [...finalEncodings.values()].reduce(
469+
(p, c) => p + c.length,
470+
0
471+
);
469472

470473
JavaScriptLauncher.LOGGER.info(
471474
`Splitting done took: ${timeInMs}, went from ${before} to ${after} test cases`
@@ -476,9 +479,11 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
476479

477480
// this.metricManager.recordProperty(PropertyName., `${timeInMs}`); // TODO new metric
478481
}
482+
479483
if (this.arguments_.testMinimization) {
480484
const start = Date.now();
481485
JavaScriptLauncher.LOGGER.info("Minimization started");
486+
// TODO
482487
const timeInMs = (Date.now() - start) / 1000;
483488
JavaScriptLauncher.LOGGER.info(`Minimization done, took: ${timeInMs}`);
484489
// this.metricManager.recordProperty(PropertyName., `${timeInMs}`); // TODO new metric
@@ -495,40 +500,50 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
495500
}
496501
);
497502

498-
const startDeduplication = Date.now();
499-
const before = [...finalEncodings.values()]
500-
.map((x) => x.length)
501-
.reduce((p, c) => p + c);
502-
JavaScriptLauncher.LOGGER.info("De-Duplication started");
503+
if (this.arguments_.testDeDuplication) {
504+
const deDuplicator = new DeDuplicator(
505+
this.userInterface,
506+
secondaryObjectives,
507+
objectives
508+
);
503509

504-
const deDuplicator = newDeDuplicator();
505-
const newArchives = deDuplicator.deDuplicate(
506-
secondaryObjectives,
507-
objectives,
508-
finalEncodings
509-
);
510+
const start = Date.now();
511+
const before = [...finalEncodings.values()].reduce(
512+
(p,c)=>p+c.length,
513+
0
514+
);
515+
JavaScriptLauncher.LOGGER.info("De-Duplication started");
510516

511-
const timeInMsDeDuplication = (Date.now() - startDeduplication) / 1000;
512-
const after = [...newArchives.values()]
513-
.map((x) => x.size)
514-
.reduce((p, c) => p + c);
517+
finalEncodings = await deDuplicator.execute(finalEncodings);
515518

516-
JavaScriptLauncher.LOGGER.info(
517-
`De-Duplication done took: ${timeInMsDeDuplication}, went from ${before} to ${after} test cases`
518-
);
519-
this.userInterface.printSuccess(
520-
`De-Duplication done took: ${timeInMsDeDuplication}, went from ${before} to ${after} test cases`
521-
);
519+
const timeInMs = (Date.now() - start) / 1000;
520+
const after = [...finalEncodings.values()].reduce(
521+
(p, c) => p + c.length,
522+
0
523+
);
522524

523-
if (this.arguments_.metaComments) {
524-
addMetaComments(newArchives);
525+
JavaScriptLauncher.LOGGER.info(
526+
`De-Duplication done took: ${timeInMs}, went from ${before} to ${after} test cases`
527+
);
528+
this.userInterface.printSuccess(
529+
`De-Duplication done took: ${timeInMs}, went from ${before} to ${after} test cases`
530+
);
525531
}
526532

527-
finalEncodings = new Map<Target, JavaScriptTestCase[]>(
528-
[...newArchives.entries()].map(([target, archive]) => {
529-
return [target, archive.getEncodings()];
530-
})
531-
);
533+
if (this.arguments_.metaComments) {
534+
const metaCommenter = new MetaCommenter(
535+
this.userInterface,
536+
secondaryObjectives,
537+
objectives
538+
);
539+
const start = Date.now();
540+
JavaScriptLauncher.LOGGER.info("Meta-Commenting started");
541+
finalEncodings = await metaCommenter.execute(finalEncodings);
542+
const timeInMs = (Date.now() - start) / 1000;
543+
544+
JavaScriptLauncher.LOGGER.info(`Meta-Commenting done took: ${timeInMs}`);
545+
this.userInterface.printSuccess(`Meta-Commenting done took: ${timeInMs}`);
546+
}
532547

533548
const suiteBuilder = new JavaScriptSuiteBuilder(
534549
this.storageManager,

‎tools/javascript/lib/workflows/DeDuplicator.ts‎

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818
import { Target } from "@syntest/analysis-javascript";
19+
import { UserInterface } from "@syntest/cli-graphics";
1920
import { IllegalStateError } from "@syntest/diagnostics";
2021
import { getLogger, Logger } from "@syntest/logging";
2122
import {
@@ -25,25 +26,59 @@ import {
2526
} from "@syntest/search";
2627
import { JavaScriptTestCase } from "@syntest/search-javascript";
2728

28-
export class DeDuplicator {
29+
import { Workflow } from "./Workflow";
30+
31+
export class DeDuplicator implements Workflow {
2932
protected static LOGGER: Logger;
30-
constructor() {
31-
DeDuplicator.LOGGER = getLogger("DeDuplicator");
32-
}
3333

34-
deDuplicate(
34+
protected userInterface: UserInterface;
35+
protected secondaryObjectives: SecondaryObjectiveComparator<JavaScriptTestCase>[];
36+
protected objectivesMap: Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>;
37+
38+
constructor(
39+
userInterface: UserInterface,
3540
secondaryObjectives: SecondaryObjectiveComparator<JavaScriptTestCase>[],
36-
objectivesMap: Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>,
41+
objectivesMap: Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>
42+
) {
43+
DeDuplicator.LOGGER = getLogger(DeDuplicator.name);
44+
this.userInterface = userInterface;
45+
this.secondaryObjectives = secondaryObjectives;
46+
this.objectivesMap = objectivesMap;
47+
}
48+
49+
// eslint-disable-next-line sonarjs/cognitive-complexity
50+
execute(
3751
encodingsMap: Map<Target, JavaScriptTestCase[]>
38-
): Map<Target, Archive<JavaScriptTestCase>> {
52+
): Promise<Map<Target, JavaScriptTestCase[]>> {
53+
const totalEncodings = [...encodingsMap.values()].reduce(
54+
(counter, value) => counter + value.length,
55+
0
56+
);
57+
this.userInterface.startProgressBars([
58+
{
59+
name: `De-Duplication`,
60+
value: 0,
61+
maxValue: totalEncodings,
62+
meta: "",
63+
},
64+
]);
65+
66+
let count = 1;
3967
const archives = new Map<Target, Archive<JavaScriptTestCase>>();
4068
for (const [target, encodings] of encodingsMap.entries()) {
41-
const objectives = objectivesMap.get(target);
69+
const objectives = this.objectivesMap.get(target);
4270

4371
const archive = new Archive<JavaScriptTestCase>();
4472
archives.set(target, archive);
4573

4674
for (const encoding of encodings) {
75+
this.userInterface.updateProgressBar({
76+
name: `De-Duplication`,
77+
value: count++,
78+
maxValue: totalEncodings,
79+
meta: "",
80+
});
81+
4782
if (!encoding.getExecutionResult()) {
4883
throw new IllegalStateError(
4984
"Invalid encoding without executionResult"
@@ -62,7 +97,7 @@ export class DeDuplicator {
6297
const currentEncoding = archive.getEncoding(objective);
6398

6499
// Look at secondary objectives when two solutions are found
65-
for (const secondaryObjective of secondaryObjectives) {
100+
for (const secondaryObjective of this.secondaryObjectives) {
66101
const comparison = secondaryObjective.compare(
67102
encoding,
68103
currentEncoding
@@ -86,6 +121,17 @@ export class DeDuplicator {
86121
}
87122
}
88123

89-
return archives;
124+
this.userInterface.stopProgressBars();
125+
126+
return new Promise((resolve) =>
127+
resolve(
128+
new Map<Target, JavaScriptTestCase[]>(
129+
[...archives.entries()].map(([target, archive]) => [
130+
target,
131+
archive.getEncodings(),
132+
])
133+
)
134+
)
135+
);
90136
}
91137
}

‎tools/javascript/lib/workflows/MetaComment.ts‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /