-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] Mutation server #4877
Closed
Closed
[DRAFT] Mutation server #4877
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a7f747b
feat: Add initial mutation server exec
jaspervdveen e7c0cb4
wip: rpc via stdout/stdin pipes
jaspervdveen cb3d107
wip: Use TCP socket instead of anonymous pipes
jaspervdveen db23058
wip: change tcp socket to web socket server
jaspervdveen 3540060
chore: send server started output
jaspervdveen 29bed47
feat: instrument returns mutation test report
jaspervdveen c10507c
refactor(server): reuse setup for subsequent instrument runs
jaspervdveen edfe4ca
feat: set websocket port via program args
jaspervdveen 85a2c42
fix: JSON-RPC error handling in StrykerServer
jaspervdveen 6ed071e
refactor: rename default test coverage to empty test coverage
jaspervdveen d2ca741
wip: Add mutate method to Stryker Server
jaspervdveen 36db521
fix: incorrect mutantresult location in instrument report
jaspervdveen 639b9b4
chore: no longer keep preparation context in memory
jaspervdveen b88f460
Merge pull request #1 from jaspervdveen/feat/mutation-server
3a8cb30
refactor: Use MutantResult array type for instrument run result
jaspervdveen 979c4e1
chore: check for mutation server method implementation
jaspervdveen 67f1a82
chore: Setup ability to send JSON-RCP notifications to client
jaspervdveen d67bb55
feat: during test run, send progress notifications
jaspervdveen b64dd6f
Merge pull request #2 from jaspervdveen/feat/mutation-testing
f38fe93
refactor: use empty reporter to forward partial results
jaspervdveen 40f7ca7
Merge pull request #3 from jaspervdveen/develop
c9d0895
refactor: Bind server methods
jaspervdveen 3ea89ae
refactor(server): Extract server methods from server class
jaspervdveen fb72288
refactor(server): Extract json-rpc and websocket logic to separate cl…
jaspervdveen df227ba
refactor(server): Introduce transporter interface
jaspervdveen a7b6ac2
chore(websocket): Pick a random available port if no port is explicit…
jaspervdveen 2ff02b2
fix(websocket): Do not overwrite existing callback on registering
jaspervdveen 32b5601
refactor(transporter): Use EventEmitter in transporter
jaspervdveen 3120511
Merge pull request #4 from jaspervdveen/feature/realtime-updates
8eb24c3
Merge branch 'stryker-mutator:master' into master
cf0006d
test(server): Add tests for StrykerServer class
jaspervdveen ebaabe7
test(MutationServerProtocolHandler): Add test for protocol handler
jaspervdveen e9bd67b
test(MutationServerProtocolHandler): Add tests for protocol handler
jaspervdveen d579d40
test(webSocketTransporter): Add tests
jaspervdveen 7eb9877
test(instrumentMethod): Add tests for InstrumentMethod class
jaspervdveen 69cd5fc
test(mutationTestMethod): Add tests for mutation test method
jaspervdveen c7145c1
test(mutantInstrumenterExecutor): Add tests for mutantInstrumenterExe…
jaspervdveen e607981
fix(mutationTestMethod): Empty reporter not reporting mutant tested e…
jaspervdveen 95ff198
test(instrumentMethod): Assert run instrumentation result
jaspervdveen b902b9d
Merge pull request #5 from jaspervdveen/test/server
48592d5
feat(server): Abort mutation test run
74ab60c
feat(server): Configure the Stryker config file uri via an initialize…
393f0ec
Fix tests, refactor mutate request, change init request (#8)
jaspervdveen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
import { StrykerServer } from '../dist/src/index.js'; | ||
|
||
process.title = 'stryker-server'; | ||
new StrykerServer(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './mutation-server-protocol-handler.js'; | ||
export * from './mutation-server-protocol.js'; | ||
export * from './server-tokens.js'; | ||
export * as serverTokens from './server-tokens.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './instrument-method.js'; | ||
export * from './mutation-test-method.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createInjector } from 'typed-inject'; | ||
import { MutantResult, PartialStrykerOptions } from '@stryker-mutator/api/core'; | ||
|
||
import { provideLogger } from './../../di/provide-logger.js'; | ||
import { PrepareExecutor } from './../../process/1-prepare-executor.js'; | ||
import { MutantInstrumenterExecutor as ServerMutantInstrumenterExecutor } from './process/mutant-instrument-executor.js'; | ||
|
||
export class InstrumentMethod { | ||
/** | ||
* Get the mutant results for the given glob patterns, without running the mutation tests. | ||
* @param globPatterns The glob patterns to instrument. | ||
* @returns The mutant results. | ||
*/ | ||
public static async runInstrumentation(options: PartialStrykerOptions, injectorFactory = createInjector): Promise<MutantResult[]> { | ||
const rootInjector = injectorFactory(); | ||
|
||
const loggerProvider = provideLogger(rootInjector); | ||
|
||
const prepareExecutor = loggerProvider.injectClass(PrepareExecutor); | ||
|
||
const mutantInstrumenterInjector = await prepareExecutor.execute(options); | ||
|
||
const mutantInstrumenter = mutantInstrumenterInjector.injectClass(ServerMutantInstrumenterExecutor); | ||
|
||
return await mutantInstrumenter.execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { createInjector } from 'typed-inject'; | ||
import { MutantResult, PartialStrykerOptions } from '@stryker-mutator/api/core'; | ||
import { commonTokens } from '@stryker-mutator/api/plugin'; | ||
|
||
import { MutationTestExecutor } from '../../process/4-mutation-test-executor.js'; | ||
import { provideLogger } from '../../di/provide-logger.js'; | ||
import { PrepareExecutor } from '../../process/1-prepare-executor.js'; | ||
import { MutantInstrumenterExecutor } from '../../process/2-mutant-instrumenter-executor.js'; | ||
import { Stryker } from '../../stryker.js'; | ||
import { BroadcastReporter } from '../../reporters/index.js'; | ||
import { DryRunExecutor } from '../../process/3-dry-run-executor.js'; | ||
import { coreTokens } from '../../di/index.js'; | ||
import { ConfigError, retrieveCause } from '../../errors.js'; | ||
import { LogConfigurator } from '../../logging/log-configurator.js'; | ||
|
||
export class MutationTestMethod { | ||
constructor(private readonly injectorFactory = createInjector) {} | ||
|
||
/** | ||
* Run a mutation test and get partial results via a callback. | ||
* @param globPatterns The glob patterns to mutation test. | ||
* @param onMutantTested A callback that is called when a mutant is tested. | ||
*/ | ||
public async runMutationTestRealtime( | ||
options: PartialStrykerOptions, | ||
abortSignal: AbortSignal, | ||
onMutantTested: (result: Readonly<MutantResult>) => void, | ||
): Promise<void> { | ||
options.reporters = ['empty']; // used to stream results | ||
|
||
const rootInjector = this.injectorFactory(); | ||
const loggerProvider = provideLogger(rootInjector); | ||
|
||
try { | ||
// 1. Prepare. Load Stryker configuration, load the input files and starts the logging server | ||
const prepareExecutor = loggerProvider.injectClass(PrepareExecutor); | ||
|
||
const mutantInstrumenterInjector = await prepareExecutor.execute(options); | ||
|
||
const broadcastReporter = mutantInstrumenterInjector.resolve(coreTokens.reporter) as BroadcastReporter; | ||
const emptyReporter = broadcastReporter.reporters.empty; | ||
if (!emptyReporter) { | ||
throw new Error('Reporter unavailable'); | ||
} | ||
|
||
emptyReporter.onMutantTested = onMutantTested; | ||
try { | ||
// 2. Mutate and instrument the files and write to the sandbox. | ||
const mutantInstrumenter = mutantInstrumenterInjector.injectClass(MutantInstrumenterExecutor); | ||
const dryRunExecutorInjector = await mutantInstrumenter.execute(); | ||
|
||
// 3. Perform a 'dry run' (initial test run). Runs the tests without active mutants and collects coverage. | ||
const dryRunExecutor = dryRunExecutorInjector.injectClass(DryRunExecutor); | ||
const mutationRunExecutorInjector = (await dryRunExecutor.execute()).provideValue(commonTokens.abortSignal, abortSignal); | ||
|
||
// 4. Actual mutation testing. Will check every mutant and if valid run it in an available test runner. | ||
const mutationRunExecutor = mutationRunExecutorInjector.injectClass(MutationTestExecutor); | ||
|
||
await mutationRunExecutor.execute(); | ||
} catch (error) { | ||
if (mutantInstrumenterInjector.resolve(commonTokens.options).cleanTempDir !== 'always') { | ||
const log = loggerProvider.resolve(commonTokens.getLogger)(Stryker.name); | ||
log.debug('Not removing the temp dir because an error occurred'); | ||
mutantInstrumenterInjector.resolve(coreTokens.temporaryDirectory).removeDuringDisposal = false; | ||
} | ||
throw error; | ||
} | ||
} catch (error) { | ||
const log = loggerProvider.resolve(commonTokens.getLogger)(Stryker.name); | ||
const cause = retrieveCause(error); | ||
if (cause instanceof ConfigError) { | ||
log.error(cause.message); | ||
} else { | ||
log.error('Unexpected error occurred while running Stryker', error); | ||
log.info('This might be a known problem with a solution documented in our troubleshooting guide.'); | ||
log.info('You can find it at https://stryker-mutator.io/docs/stryker-js/troubleshooting/'); | ||
if (!log.isTraceEnabled()) { | ||
log.info( | ||
'Still having trouble figuring out what went wrong? Try `npx stryker run --fileLogLevel trace --logLevel debug` to get some more info.', | ||
); | ||
} | ||
} | ||
throw cause; | ||
} finally { | ||
await rootInjector.dispose(); | ||
await LogConfigurator.shutdown(); | ||
} | ||
} | ||
|
||
/** | ||
* Run a mutation test. | ||
* @param globPatterns The glob patterns to mutation test. | ||
* @returns The mutant results. | ||
*/ | ||
public static async runMutationTest(abortSignal: AbortSignal, options: PartialStrykerOptions): Promise<MutantResult[]> { | ||
return await new Stryker(options).runMutationTest(abortSignal); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of the
Stryker
class. Why have 2 separate processes for the same thing? I think we should reuse theStryker
class.