Skip to content

Commit

Permalink
feat: completely overhoal workflows (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstallenberg committed Dec 11, 2023
1 parent 5b5f655 commit 7072ea5
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 112 deletions.
89 changes: 52 additions & 37 deletions tools/javascript/lib/JavaScriptLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import { StorageManager } from "@syntest/storage";

import { TestCommandOptions } from "./commands/test";
import { DeDuplicator } from "./workflows/DeDuplicator";
import { addMetaComments } from "./workflows/MetaComment";
import { MetaCommenter } from "./workflows/MetaCommenter";
import { TestSplitting } from "./workflows/TestSplitter";

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

if (this.arguments_.testSplitting) {
const testSplitter = new TestSplitting(this.userInterface, this.runner);

const start = Date.now();
const before = [...finalEncodings.values()]
.map((x) => x.length)
.reduce((p, c) => p + c);
const before = [...finalEncodings.values()].reduce(
(p, c) => p + c.length,
0
);
JavaScriptLauncher.LOGGER.info("Splitting started");
finalEncodings = await testSplitter.testSplitting(finalEncodings);
finalEncodings = await testSplitter.execute(finalEncodings);

const timeInMs = (Date.now() - start) / 1000;
const after = [...finalEncodings.values()]
.map((x) => x.length)
.reduce((p, c) => p + c);
const after = [...finalEncodings.values()].reduce(
(p, c) => p + c.length,
0
);

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

// this.metricManager.recordProperty(PropertyName., `${timeInMs}`); // TODO new metric
}

if (this.arguments_.testMinimization) {
const start = Date.now();
JavaScriptLauncher.LOGGER.info("Minimization started");
// TODO
const timeInMs = (Date.now() - start) / 1000;
JavaScriptLauncher.LOGGER.info(`Minimization done, took: ${timeInMs}`);
// this.metricManager.recordProperty(PropertyName., `${timeInMs}`); // TODO new metric
Expand All @@ -495,40 +500,50 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
}
);

const startDeduplication = Date.now();
const before = [...finalEncodings.values()]
.map((x) => x.length)
.reduce((p, c) => p + c);
JavaScriptLauncher.LOGGER.info("De-Duplication started");
if (this.arguments_.testDeDuplication) {
const deDuplicator = new DeDuplicator(
this.userInterface,
secondaryObjectives,
objectives
);

const deDuplicator = new DeDuplicator();
const newArchives = deDuplicator.deDuplicate(
secondaryObjectives,
objectives,
finalEncodings
);
const start = Date.now();
const before = [...finalEncodings.values()].reduce(
(p, c) => p + c.length,
0
);
JavaScriptLauncher.LOGGER.info("De-Duplication started");

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

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

if (this.arguments_.metaComments) {
addMetaComments(newArchives);
JavaScriptLauncher.LOGGER.info(
`De-Duplication done took: ${timeInMs}, went from ${before} to ${after} test cases`
);
this.userInterface.printSuccess(
`De-Duplication done took: ${timeInMs}, went from ${before} to ${after} test cases`
);
}

finalEncodings = new Map<Target, JavaScriptTestCase[]>(
[...newArchives.entries()].map(([target, archive]) => {
return [target, archive.getEncodings()];
})
);
if (this.arguments_.metaComments) {
const metaCommenter = new MetaCommenter(
this.userInterface,
secondaryObjectives,
objectives
);
const start = Date.now();
JavaScriptLauncher.LOGGER.info("Meta-Commenting started");
finalEncodings = await metaCommenter.execute(finalEncodings);
const timeInMs = (Date.now() - start) / 1000;

JavaScriptLauncher.LOGGER.info(`Meta-Commenting done took: ${timeInMs}`);
this.userInterface.printSuccess(`Meta-Commenting done took: ${timeInMs}`);
}

const suiteBuilder = new JavaScriptSuiteBuilder(
this.storageManager,
Expand Down
66 changes: 56 additions & 10 deletions tools/javascript/lib/workflows/DeDuplicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/
import { Target } from "@syntest/analysis-javascript";
import { UserInterface } from "@syntest/cli-graphics";
import { IllegalStateError } from "@syntest/diagnostics";
import { getLogger, Logger } from "@syntest/logging";
import {
Expand All @@ -25,25 +26,59 @@ import {
} from "@syntest/search";
import { JavaScriptTestCase } from "@syntest/search-javascript";

export class DeDuplicator {
import { Workflow } from "./Workflow";

export class DeDuplicator implements Workflow {
protected static LOGGER: Logger;
constructor() {
DeDuplicator.LOGGER = getLogger("DeDuplicator");
}

deDuplicate(
protected userInterface: UserInterface;
protected secondaryObjectives: SecondaryObjectiveComparator<JavaScriptTestCase>[];
protected objectivesMap: Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>;

constructor(
userInterface: UserInterface,
secondaryObjectives: SecondaryObjectiveComparator<JavaScriptTestCase>[],
objectivesMap: Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>,
objectivesMap: Map<Target, ObjectiveFunction<JavaScriptTestCase>[]>
) {
DeDuplicator.LOGGER = getLogger(DeDuplicator.name);
this.userInterface = userInterface;
this.secondaryObjectives = secondaryObjectives;
this.objectivesMap = objectivesMap;
}

// eslint-disable-next-line sonarjs/cognitive-complexity
execute(
encodingsMap: Map<Target, JavaScriptTestCase[]>
): Map<Target, Archive<JavaScriptTestCase>> {
): Promise<Map<Target, JavaScriptTestCase[]>> {
const totalEncodings = [...encodingsMap.values()].reduce(
(counter, value) => counter + value.length,
0
);
this.userInterface.startProgressBars([
{
name: `De-Duplication`,
value: 0,
maxValue: totalEncodings,
meta: "",
},
]);

let count = 1;
const archives = new Map<Target, Archive<JavaScriptTestCase>>();
for (const [target, encodings] of encodingsMap.entries()) {
const objectives = objectivesMap.get(target);
const objectives = this.objectivesMap.get(target);

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

for (const encoding of encodings) {
this.userInterface.updateProgressBar({
name: `De-Duplication`,
value: count++,
maxValue: totalEncodings,
meta: "",
});

if (!encoding.getExecutionResult()) {
throw new IllegalStateError(
"Invalid encoding without executionResult"
Expand All @@ -62,7 +97,7 @@ export class DeDuplicator {
const currentEncoding = archive.getEncoding(objective);

// Look at secondary objectives when two solutions are found
for (const secondaryObjective of secondaryObjectives) {
for (const secondaryObjective of this.secondaryObjectives) {
const comparison = secondaryObjective.compare(
encoding,
currentEncoding
Expand All @@ -86,6 +121,17 @@ export class DeDuplicator {
}
}

return archives;
this.userInterface.stopProgressBars();

return new Promise((resolve) =>
resolve(
new Map<Target, JavaScriptTestCase[]>(
[...archives.entries()].map(([target, archive]) => [
target,
archive.getEncodings(),
])
)
)
);
}
}
56 changes: 0 additions & 56 deletions tools/javascript/lib/workflows/MetaComment.ts

This file was deleted.

0 comments on commit 7072ea5

Please sign in to comment.