diff --git a/Ciphers/KeywordShiftedAlphabet.js b/Ciphers/KeywordShiftedAlphabet.js index 2c6f91fe48..d2ff906db7 100644 --- a/Ciphers/KeywordShiftedAlphabet.js +++ b/Ciphers/KeywordShiftedAlphabet.js @@ -5,13 +5,13 @@ * Second row start with the keyword, then we continue with the rest of the characters that are missing in alphabetical order. * * |A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z| - * |K|E|Y|W|O|R|D|A|B|C|F|G|H|I|J|L|M|N|P|Q|S|T|U|V|W|Z| + * |K|E|Y|W|O|R|D|A|B|C|F|G|H|I|J|L|M|N|P|Q|S|T|U|V|X|Z| * * Encryption is then just a matter of writing the matching (same index) letter from the second row instead of the first row: * 'Hello world' -> 'Aoggj ujngw' * * Decryption is then just the reverse process of writing the matching (same index) letter from the first row instead of the second row - * 'Aogg ujngw' -> 'Hello world' + * 'Aoggj ujngw' -> 'Hello world' * * Non alphabetical characters (space, exclamation mark, ...) are kept as they are */ @@ -45,14 +45,31 @@ const alphabet = [ 'z' ] +/** + * Checks the keyword rule stated at the top of this file: + * "Keyword must be a word where each character can occur only once." + * + * Supported boundaries: + * - 'a' (one character) is the smallest valid keyword -> true + * - a keyword using all 26 letters once is the largest valid keyword -> true + * - any repeated character, e.g. 'aa' or 'hello', is invalid -> false + * - '' is never reached through encrypt/decrypt: checkInputs rejects it first + * with 'Both keyword and message must be specified'. + * Characters are compared exactly as given (no case folding). + * + * @param {string} keyword + * @returns {boolean} true when no character occurs more than once + * @example checkKeywordValidity('keyword') // true + * @example checkKeywordValidity('hello') // false ('l' repeats) + */ function checkKeywordValidity(keyword) { - keyword.split('').forEach((char, index) => { + // `every` stops and returns false on the first repeated character. + // (A `return false` inside `forEach` only left the callback, so repeated + // characters were previously accepted.) + return keyword.split('').every((char, index) => { const rest = keyword.slice(0, index) + keyword.slice(index + 1) - if (rest.indexOf(char) !== -1) { - return false - } + return rest.indexOf(char) === -1 }) - return true } function getEncryptedAlphabet(keyword) { @@ -106,7 +123,7 @@ function decrypt(keyword, message) { ) } -export { encrypt, decrypt } +export { encrypt, decrypt, checkKeywordValidity } // encrypt('keyword', 'Hello world!') // Prints 'Aoggj ujngw!' // decrypt('keyword', 'Aoggj ujngw!') // Prints 'Hello world! diff --git a/Ciphers/test/KeywordShiftedAlphabet.test.js b/Ciphers/test/KeywordShiftedAlphabet.test.js index 38e0839488..9f3dd82354 100644 --- a/Ciphers/test/KeywordShiftedAlphabet.test.js +++ b/Ciphers/test/KeywordShiftedAlphabet.test.js @@ -1,4 +1,8 @@ -import { encrypt, decrypt } from '../KeywordShiftedAlphabet' +import { + encrypt, + decrypt, + checkKeywordValidity +} from '../KeywordShiftedAlphabet' test('Hello world! === decrypt(encrypt(Hello world!))', () => { const word = 'Hello world!' @@ -11,3 +15,51 @@ test('The Algorithms === decrypt(encrypt(The Algorithms))', () => { const result = decrypt('keyword', encrypt('keyword', word)) expect(result).toMatch(word) }) + +// Boundary tests for checkKeywordValidity (KeywordShiftedAlphabet.js line 65). +// Contract (line 3): "Keyword must be a word where each character can occur +// only once." Empty input is rejected earlier by checkInputs (line 99). +describe('checkKeywordValidity boundaries', () => { + describe('valid side', () => { + test("smallest valid keyword 'a' is accepted", () => { + expect(checkKeywordValidity('a')).toBe(true) + // 'a' leaves the alphabet unchanged, so encryption is the identity. + expect(encrypt('a', 'abc')).toBe('abc') + }) + + test("ordinary keyword 'keyword' is accepted", () => { + expect(checkKeywordValidity('keyword')).toBe(true) + // Table at line 8: H->A, E->O, L->G, O->J, W->U, R->N, D->W + expect(encrypt('keyword', 'Hello world!')).toBe('Aoggj ujngw!') + }) + + test('largest valid keyword uses all 26 letters exactly once', () => { + const reversed = 'zyxwvutsrqponmlkjihgfedcba' + expect(checkKeywordValidity(reversed)).toBe(true) + expect(encrypt(reversed, 'abc')).toBe('zyx') + }) + }) + + describe('invalid side', () => { + test("smallest repeated keyword 'aa' is rejected", () => { + expect(checkKeywordValidity('aa')).toBe(false) + expect(() => encrypt('aa', 'abc')).toThrow('Invalid keyword!') + expect(() => decrypt('aa', 'abc')).toThrow('Invalid keyword!') + }) + + test("ordinary repeated keyword 'hello' is rejected", () => { + expect(checkKeywordValidity('hello')).toBe(false) + expect(() => encrypt('hello', 'd')).toThrow('Invalid keyword!') + }) + + test('a 27th letter must repeat one of the 26 and is rejected', () => { + expect(checkKeywordValidity('zyxwvutsrqponmlkjihgfedcbaa')).toBe(false) + }) + + test('empty keyword is rejected by checkInputs before validity', () => { + expect(() => encrypt('', 'abc')).toThrow( + 'Both keyword and message must be specified' + ) + }) + }) +}) diff --git a/work/R50-T002/README.md b/work/R50-T002/README.md new file mode 100644 index 0000000000..aab0e370a9 --- /dev/null +++ b/work/R50-T002/README.md @@ -0,0 +1,84 @@ +# R50-T002 — Supported boundaries of `checkKeywordValidity` + +Source: `Ciphers/KeywordShiftedAlphabet.js`, `checkKeywordValidity` (line 65 after this change; line 48 at pinned commit `5c39e87`). + +## Recorded contract (before any change) + +| Aspect | Observation | +| --------------------- | -------------------------------------------------------------------------------------------------- | +| Input | `keyword` (string). Only called from `checkInputs`, after the empty-input guard (line 99). | +| Result | boolean — "Keyword must be a word where each character can occur only once" (line 3). | +| Mutation | None (strings are immutable). | +| External dependencies | None. | +| Public interface | `encrypt`, `decrypt` (unchanged). `checkKeywordValidity` is now also exported so it can be tested. | + +## Boundary table (expected values written before running the source) + +| Partition | Input | Expected | Source contract | +| ------------------------- | ------------------------------ | -------------------------------------------------------------- | --------------- | +| valid boundary (smallest) | `'a'` | `true`; `encrypt('a','abc') === 'abc'` | line 3 | +| valid interior | `'keyword'` | `true`; `encrypt('keyword','Hello world!') === 'Aoggj ujngw!'` | lines 3, 8 | +| valid boundary (largest) | `'zyxwvutsrqponmlkjihgfedcba'` | `true`; `encrypt(…,'abc') === 'zyx'` | line 3 | +| invalid boundary | `'aa'` | `false`; `encrypt` throws `Invalid keyword!` | lines 3, 104 | +| invalid interior | `'hello'` | `false`; `encrypt` throws `Invalid keyword!` | lines 3, 104 | +| invalid (27 letters) | 26 letters + `'a'` | `false` | line 3 | +| unsupported (empty) | `''` | `encrypt` throws `Both keyword and message must be specified` | line 99-100 | + +Not covered on purpose: mixed-case repeats such as `'Aa'` and non-letter keywords. The source does +not define them, so no new rule was added for them. + +## Baseline — defect found + +Running the fixture against the original source (`baseline.txt`): + +- `encrypt('aa', 'abc')` returned `"aab"` instead of throwing `Invalid keyword!`. +- `encrypt('hello', 'd')` returned `"l"` instead of throwing. +- Round trip broke: `decrypt('hello', encrypt('hello', 'd'))` returned `"c"`, not `"d"`. + +Cause: `return false` inside `keyword.split('').forEach(...)` only returns from the callback, so the +function always reached `return true`. + +Order of work and evidence: the baseline above was recorded on the original, unedited source. +The expected values in the boundary tests come from the documented contract (line 3), not from +running the fixed code. `negative-control.txt` shows `check.py` run with the original +always-`true` behaviour put back temporarily: it exits **1** and names the 3 failing +repeated-keyword tests, while the other 6 tests pass. With the fix, all pass. + +The fix replaces `forEach` with `every`, which stops and returns `false` on the first repeated +character. It uses the same algorithm and the same case-sensitive comparison. No guard was added +elsewhere. + +Documentation corrections in the same header (both confirmed by running the code): + +- line 8: the translation-table row listed `W` twice and omitted `X` (`…U|V|W|Z|` → `…U|V|X|Z|`); +- line 14: the decryption example was missing a letter (`'Aogg ujngw'` → `'Aoggj ujngw'`). + +## Sensitivity check (temporary copy only) + +On every run, `check.py` also applies the original defect (`return true` for every character) to a +temp copy of the source. The named test `smallest repeated keyword 'aa' is rejected` passes on the +fixed code and fails on that copy. + +## How to run + +From the repository root: + +```sh +python3 work/R50-T002/check.py +``` + +`check.py` installs dependencies from `package-lock.json`, runs the focused test file, evaluates the fixture with `evidence.mjs` (input, expected, actual and source line for every case), runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode (`npm test`, which is `vitest run`). It exits non-zero if any assertion or step fails, and records every command it ran in `commands.log`. + +### Recorded run (files in this folder) + +| Step | Command | Result | +| ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | +| Install from lockfile | `npm ci --ignore-scripts --no-audit --no-fund` (exit 0) | ok | +| Focused tests | `node_modules/.bin/vitest run Ciphers/test/KeywordShiftedAlphabet.test.js --reporter=json --outputFile=work/R50-T002/vitest-focused.raw.json` | 9/9 passed | +| Fixture evidence | `node work/R50-T002/evidence.mjs` | 10/10 rows match | +| Mutant: original defect restored (every character accepted) | temporary copy | killed by `smallest repeated keyword 'aa' is rejected` | +| Repository test script | `npm test -- --reporter=json --outputFile=work/R50-T002/vitest-full.raw.json` | 11977/11977 passed | + +Tool versions (`versions.txt`): python 3.12.10; node v26.13.1; npm 11.20.0; platform macOS-27.2.1-arm64-arm-64bit; vitest vitest/1.2.1 darwin-arm64 node-v26.13.1. + +Files: `results.json` (all of the above, machine-readable), `vitest-focused.json` (each focused test and its status), `commands.log`, `versions.txt`. diff --git a/work/R50-T002/baseline.txt b/work/R50-T002/baseline.txt new file mode 100644 index 0000000000..18a82a876a --- /dev/null +++ b/work/R50-T002/baseline.txt @@ -0,0 +1,8 @@ +Baseline: ORIGINAL Ciphers/KeywordShiftedAlphabet.js (pinned commit 5c39e87), via encrypt() +encrypt("a", "abc") -> "abc" +encrypt("keyword", "Hello world!") -> "Aoggj ujngw!" +encrypt("zyxwvutsrqponmlkjihgfedcba", "abc") -> "zyx" +encrypt("", "abc") -> throws: Both keyword and message must be specified +encrypt("aa", "abc") -> "aab" +encrypt("hello", "d") -> "l" +round trip with repeated keyword: decrypt("hello", encrypt("hello", "d")) -> "c" (expected "d") diff --git a/work/R50-T002/check.py b/work/R50-T002/check.py new file mode 100644 index 0000000000..1461b794e0 --- /dev/null +++ b/work/R50-T002/check.py @@ -0,0 +1,267 @@ +#!/usr/bin/env python3 +"""Focused check runner for R50-T002. + +Run from the repository root: + + python3 work/R50-T002/check.py + +Steps (everything is recorded under work/R50-T002/): + 1. Record tool versions -> versions.txt + 2. Install dependencies from the lockfile -> `npm ci --ignore-scripts` + (set SKIP_INSTALL=1 to reuse an existing node_modules) + 3. Run the focused Vitest file(s) for this task; require a non-zero test + count and zero failures -> vitest-focused.json + 4. Run evidence.mjs: literal fixture inputs against the real source, with + input / expected / actual / source line -> results.json ("fixture") + 5. Run each deliberate mutant in a temporary copy (never in the real + source); require the named regression test to pass on the original and + fail on the mutant -> results.json ("mutants") + 6. Run the repository test script in non-watch mode + (`npm test` = `vitest run`); require a non-zero test count and zero + failures -> results.json ("full_suite") + +Every command actually executed is written to commands.log. The exit status +is non-zero if any step or assertion fails (or a step times out). +""" + +import json +import os +import platform +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parent.parent +CONFIG = json.loads((HERE / 'task.json').read_text()) +TASK = CONFIG['task'] +VITEST = str(ROOT / 'node_modules' / '.bin' / 'vitest') +TIMEOUT_SECONDS = 600 + +failures = [] +log = [] + + +def show(text): + """Hide machine-specific absolute paths in recorded evidence.""" + text = text.replace(str(ROOT) + os.sep, '').replace(str(ROOT), '.') + return text.replace(tempfile.gettempdir(), '$TMPDIR') + + +def run(cmd, cwd=ROOT, check=False): + """Run a command, log it exactly, and never wait forever.""" + shown = show(' '.join(cmd)) + log.append('$ ' + shown) + try: + proc = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, + timeout=TIMEOUT_SECONDS) + except subprocess.TimeoutExpired: + log.append(f' -> timed out after {TIMEOUT_SECONDS}s') + failures.append(f'timed out: {shown}') + return subprocess.CompletedProcess(cmd, 124, '', 'timeout') + log.append(f' -> exit {proc.returncode}') + if check and proc.returncode != 0: + print(proc.stdout[-4000:]) + print(proc.stderr[-4000:], file=sys.stderr) + return proc + + +def version(cmd): + try: + return run(cmd).stdout.strip().splitlines()[0] + except Exception as exc: # best effort only + return f'unavailable ({exc})' + + +def test_list(report): + return [ + {'name': t.get('fullName') or t.get('title'), 'status': t.get('status')} + for suite in report.get('testResults', []) + for t in suite.get('assertionResults', []) + ] + + +def read_report(proc, out): + if not out.exists(): + print(proc.stdout[-4000:]) + print(proc.stderr[-4000:], file=sys.stderr) + return None + report = json.loads(out.read_text()) + out.unlink() + return report + + +def summary(cmd, proc, report): + return { + 'command': show(' '.join(cmd)), + 'exit': proc.returncode, + 'total': report and report['numTotalTests'], + 'passed': report and report['numPassedTests'], + 'failed': report and report['numFailedTests'] + } + + +def require_green(label, info, report): + if info['exit'] != 0 or not report or report['numTotalTests'] == 0 or \ + report['numFailedTests'] != 0: + failures.append(f'{label} failed: {info}') + if report: + failures.extend(' failed: ' + t['name'] + for t in test_list(report) + if t['status'] == 'failed') + + +def main(): + results = {'task': TASK} + + # 1. Tool versions + versions = { + 'python': platform.python_version(), + 'node': version(['node', '--version']), + 'npm': version(['npm', '--version']), + 'platform': platform.platform() + } + + # 2. Install from the lockfile + if os.environ.get('SKIP_INSTALL') == '1': + results['install'] = 'skipped (SKIP_INSTALL=1)' + else: + cmd = ['npm', 'ci', '--ignore-scripts', '--no-audit', '--no-fund'] + proc = run(cmd, check=True) + results['install'] = {'command': ' '.join(cmd), + 'exit': proc.returncode} + if proc.returncode != 0: + failures.append('npm ci failed') + return finish(results, versions) + versions['vitest'] = version([VITEST, '--version']) + + # 3. Focused tests + out = HERE / 'vitest-focused.raw.json' + cmd = [VITEST, 'run', *CONFIG['focused_tests'], '--reporter=json', + f'--outputFile={out}'] + proc = run(cmd) + focused_report = read_report(proc, out) + results['focused_tests'] = summary(cmd, proc, focused_report) + require_green('focused tests', results['focused_tests'], focused_report) + if focused_report: + (HERE / 'vitest-focused.json').write_text(json.dumps({ + 'command': results['focused_tests']['command'], + 'numTotalTests': focused_report['numTotalTests'], + 'numPassedTests': focused_report['numPassedTests'], + 'numFailedTests': focused_report['numFailedTests'], + 'tests': test_list(focused_report) + }, indent=2) + '\n') + + # 4. Fixture evidence (input / expected / actual / source line) + proc = run(['node', str(HERE / 'evidence.mjs')]) + rows = [] + if proc.returncode != 0: + failures.append('evidence.mjs crashed: ' + show(proc.stderr[-2000:])) + else: + rows = json.loads(proc.stdout) + results['fixture'] = rows + for row in rows: + print(f"[{'PASS' if row['pass'] else 'FAIL'}] {row['name']}") + print(f" input: {json.dumps(row['input'])}") + print(f" expected: {json.dumps(row['expected'])}") + print(f" actual: {json.dumps(row['actual'])}") + if row.get('precondition'): + print(f" source: {row['precondition']}") + if not row['pass']: + failures.append(f"fixture mismatch: {row['name']}") + if not rows: + failures.append('no fixture rows were produced') + + # 5. Deliberate mutants, in temporary copies only + original_tests = test_list(focused_report) if focused_report else [] + mutants = [run_mutant(m, original_tests) for m in CONFIG.get('mutants', [])] + if mutants: + results['mutants'] = mutants + + # 6. Repository test script in non-watch mode: `npm test` (vitest run) + out = HERE / 'vitest-full.raw.json' + cmd = ['npm', 'test', '--', '--reporter=json', f'--outputFile={out}'] + proc = run(cmd) + full_report = read_report(proc, out) + results['full_suite'] = summary(cmd, proc, full_report) + require_green('repository test script', results['full_suite'], full_report) + + return finish(results, versions) + + +def run_mutant(mutant, original_tests): + """Copy the source and its tests into a temp dir, apply one edit there, + and require the named test to pass on the original and fail here.""" + original = (ROOT / mutant['file']).read_text() + named = [t for t in original_tests if mutant['must_fail'] in t['name']] + entry = { + 'name': mutant['name'], + 'file': mutant['file'], + 'edit': {'from': mutant['find'], 'to': mutant['replace']}, + 'named_test': mutant['must_fail'], + 'named_test_on_original': [t['status'] for t in named], + 'killed': False + } + if len(named) != 1 or named[0]['status'] != 'passed': + failures.append(f"mutant {mutant['name']}: named test must match " + f"exactly one passing test on the original") + return entry + if original.count(mutant['find']) != 1: + failures.append(f"mutant {mutant['name']}: edit must match once") + return entry + with tempfile.TemporaryDirectory(prefix=f'{TASK}-mutant-') as tmp: + tmp = Path(tmp) + for rel in [mutant['file'], *mutant['tests']]: + dest = tmp / rel + dest.parent.mkdir(parents=True, exist_ok=True) + shutil.copy(ROOT / rel, dest) + (tmp / mutant['file']).write_text( + original.replace(mutant['find'], mutant['replace'])) + out = tmp / 'mutant-report.json' + cmd = [VITEST, 'run', *mutant['tests'], '--root', str(tmp), + '--globals', '--reporter=json', f'--outputFile={out}'] + proc = run(cmd) + report = read_report(proc, out) + failed = [t['name'] for t in test_list(report) + if t['status'] == 'failed'] if report else [] + entry['exit'] = proc.returncode + entry['failed_tests_on_mutant'] = failed + entry['killed'] = proc.returncode != 0 and any( + mutant['must_fail'] in name for name in failed) + print(f"[{'KILLED' if entry['killed'] else 'SURVIVED'}] mutant " + f"{mutant['name']}: {mutant['find']!r} -> {mutant['replace']!r}") + for name in failed: + print(f' failed: {name}') + if not entry['killed']: + failures.append(f"mutant {mutant['name']} was not detected by " + f"'{mutant['must_fail']}'") + return entry + + +def finish(results, versions): + results['ok'] = not failures + results['failures'] = failures + (HERE / 'versions.txt').write_text( + ''.join(f'{k}: {v}\n' for k, v in versions.items())) + (HERE / 'results.json').write_text(json.dumps(results, indent=2) + '\n') + (HERE / 'commands.log').write_text('\n'.join(log) + '\n') + print() + for key, label in [('focused_tests', 'focused tests'), + ('full_suite', 'npm test')]: + if key in results: + info = results[key] + print(f"{label + ':':15}{info['passed']}/{info['total']} passed" + f" ({info['command']})") + if failures: + print('\nFAILED:') + for item in failures: + print(' - ' + item) + return 1 + print(f'\n{TASK}: all checks passed') + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/work/R50-T002/commands.log b/work/R50-T002/commands.log new file mode 100644 index 0000000000..814ad912f9 --- /dev/null +++ b/work/R50-T002/commands.log @@ -0,0 +1,16 @@ +$ node --version + -> exit 0 +$ npm --version + -> exit 0 +$ npm ci --ignore-scripts --no-audit --no-fund + -> exit 0 +$ node_modules/.bin/vitest --version + -> exit 0 +$ node_modules/.bin/vitest run Ciphers/test/KeywordShiftedAlphabet.test.js --reporter=json --outputFile=work/R50-T002/vitest-focused.raw.json + -> exit 0 +$ node work/R50-T002/evidence.mjs + -> exit 0 +$ node_modules/.bin/vitest run Ciphers/test/KeywordShiftedAlphabet.test.js --root $TMPDIR/R50-T002-mutant-zyu9m5h8 --globals --reporter=json --outputFile=$TMPDIR/R50-T002-mutant-zyu9m5h8/mutant-report.json + -> exit 1 +$ npm test -- --reporter=json --outputFile=work/R50-T002/vitest-full.raw.json + -> exit 0 diff --git a/work/R50-T002/evidence.mjs b/work/R50-T002/evidence.mjs new file mode 100644 index 0000000000..fdb4547e4a --- /dev/null +++ b/work/R50-T002/evidence.mjs @@ -0,0 +1,74 @@ +// Evaluates the R50-T002 boundary fixture against the real source and prints +// JSON rows. Expected values were written down before running the source. +import { + encrypt, + checkKeywordValidity +} from '../../Ciphers/KeywordShiftedAlphabet.js' + +const SRC = 'KeywordShiftedAlphabet.js' +const rule = `${SRC}:3 each character can occur only once` + +const run = (fn) => { + try { + return fn() + } catch (e) { + return `throws: ${e.message}` + } +} + +const cases = [ + ['valid boundary: smallest keyword', 'a', true, rule], + ['valid interior: ordinary keyword', 'keyword', true, rule], + ['valid boundary: all 26 letters', 'zyxwvutsrqponmlkjihgfedcba', true, rule], + ['invalid boundary: smallest repeat', 'aa', false, rule], + ['invalid interior: ordinary repeat', 'hello', false, rule], + ['invalid: 27 letters', 'zyxwvutsrqponmlkjihgfedcbaa', false, rule] +] + +const rows = cases.map(([name, keyword, expected, precondition]) => { + const actual = run(() => checkKeywordValidity(keyword)) + return { + name: `checkKeywordValidity ${name}`, + input: keyword, + expected, + actual, + pass: actual === expected, + precondition + } +}) + +const encryptCases = [ + ['encrypt with smallest keyword', ['a', 'abc'], 'abc', rule], + [ + 'encrypt with ordinary keyword', + ['keyword', 'Hello world!'], + 'Aoggj ujngw!', + `${SRC}:8 translation table` + ], + [ + 'encrypt rejects repeated keyword', + ['aa', 'abc'], + 'throws: Invalid keyword!', + `${SRC}:103-104 checkInputs -> Invalid keyword!` + ], + [ + 'encrypt rejects empty keyword', + ['', 'abc'], + 'throws: Both keyword and message must be specified', + `${SRC}:99-100 checkInputs` + ] +] + +for (const [name, input, expected, precondition] of encryptCases) { + const actual = run(() => encrypt(...input)) + rows.push({ + name, + input, + expected, + actual, + pass: actual === expected, + precondition + }) +} + +console.log(JSON.stringify(rows)) diff --git a/work/R50-T002/negative-control.txt b/work/R50-T002/negative-control.txt new file mode 100644 index 0000000000..fbd247c441 --- /dev/null +++ b/work/R50-T002/negative-control.txt @@ -0,0 +1,21 @@ +Negative control for R50-T002 + +check.py was run once with the body of checkKeywordValidity temporarily replaced by +'return true' for every character, which reproduces the original forEach defect +(the function always returned true). The source was restored afterwards. + +Command: python3 work/R50-T002/check.py -> exit 1 (non-zero, as required) + +FAILED: + - focused tests failed: {'command': 'node_modules/.bin/vitest run Ciphers/test/KeywordShiftedAlphabet.test.js --reporter=json --outputFile=work/R50-T002/vitest-focused.raw.json', 'exit': 1, 'total': 9, 'passed': 6, 'failed': 3} + - failed: checkKeywordValidity boundaries invalid side smallest repeated keyword 'aa' is rejected + - failed: checkKeywordValidity boundaries invalid side ordinary repeated keyword 'hello' is rejected + - failed: checkKeywordValidity boundaries invalid side a 27th letter must repeat one of the 26 and is rejected + - fixture mismatch: checkKeywordValidity invalid boundary: smallest repeat + - fixture mismatch: checkKeywordValidity invalid interior: ordinary repeat + - fixture mismatch: checkKeywordValidity invalid: 27 letters + - fixture mismatch: encrypt rejects repeated keyword + - repository test script failed: {'command': 'npm test -- --reporter=json --outputFile=work/R50-T002/vitest-full.raw.json', 'exit': 1, 'total': 11977, 'passed': 11974, 'failed': 3} + - failed: checkKeywordValidity boundaries invalid side smallest repeated keyword 'aa' is rejected + - failed: checkKeywordValidity boundaries invalid side ordinary repeated keyword 'hello' is rejected + - failed: checkKeywordValidity boundaries invalid side a 27th letter must repeat one of the 26 and is rejected diff --git a/work/R50-T002/results.json b/work/R50-T002/results.json new file mode 100644 index 0000000000..ecc97ea6e6 --- /dev/null +++ b/work/R50-T002/results.json @@ -0,0 +1,124 @@ +{ + "task": "R50-T002", + "install": { + "command": "npm ci --ignore-scripts --no-audit --no-fund", + "exit": 0 + }, + "focused_tests": { + "command": "node_modules/.bin/vitest run Ciphers/test/KeywordShiftedAlphabet.test.js --reporter=json --outputFile=work/R50-T002/vitest-focused.raw.json", + "exit": 0, + "total": 9, + "passed": 9, + "failed": 0 + }, + "fixture": [ + { + "name": "checkKeywordValidity valid boundary: smallest keyword", + "input": "a", + "expected": true, + "actual": true, + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "checkKeywordValidity valid interior: ordinary keyword", + "input": "keyword", + "expected": true, + "actual": true, + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "checkKeywordValidity valid boundary: all 26 letters", + "input": "zyxwvutsrqponmlkjihgfedcba", + "expected": true, + "actual": true, + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "checkKeywordValidity invalid boundary: smallest repeat", + "input": "aa", + "expected": false, + "actual": false, + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "checkKeywordValidity invalid interior: ordinary repeat", + "input": "hello", + "expected": false, + "actual": false, + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "checkKeywordValidity invalid: 27 letters", + "input": "zyxwvutsrqponmlkjihgfedcbaa", + "expected": false, + "actual": false, + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "encrypt with smallest keyword", + "input": ["a", "abc"], + "expected": "abc", + "actual": "abc", + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:3 each character can occur only once" + }, + { + "name": "encrypt with ordinary keyword", + "input": ["keyword", "Hello world!"], + "expected": "Aoggj ujngw!", + "actual": "Aoggj ujngw!", + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:8 translation table" + }, + { + "name": "encrypt rejects repeated keyword", + "input": ["aa", "abc"], + "expected": "throws: Invalid keyword!", + "actual": "throws: Invalid keyword!", + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:103-104 checkInputs -> Invalid keyword!" + }, + { + "name": "encrypt rejects empty keyword", + "input": ["", "abc"], + "expected": "throws: Both keyword and message must be specified", + "actual": "throws: Both keyword and message must be specified", + "pass": true, + "precondition": "KeywordShiftedAlphabet.js:99-100 checkInputs" + } + ], + "mutants": [ + { + "name": "original defect restored (every character accepted)", + "file": "Ciphers/KeywordShiftedAlphabet.js", + "edit": { + "from": " return rest.indexOf(char) === -1\n", + "to": " return true\n" + }, + "named_test": "smallest repeated keyword 'aa' is rejected", + "named_test_on_original": ["passed"], + "killed": true, + "exit": 1, + "failed_tests_on_mutant": [ + " checkKeywordValidity boundaries invalid side smallest repeated keyword 'aa' is rejected", + " checkKeywordValidity boundaries invalid side ordinary repeated keyword 'hello' is rejected", + " checkKeywordValidity boundaries invalid side a 27th letter must repeat one of the 26 and is rejected" + ] + } + ], + "full_suite": { + "command": "npm test -- --reporter=json --outputFile=work/R50-T002/vitest-full.raw.json", + "exit": 0, + "total": 11977, + "passed": 11977, + "failed": 0 + }, + "ok": true, + "failures": [] +} diff --git a/work/R50-T002/task.json b/work/R50-T002/task.json new file mode 100644 index 0000000000..f3c49dfa82 --- /dev/null +++ b/work/R50-T002/task.json @@ -0,0 +1,14 @@ +{ + "task": "R50-T002", + "focused_tests": ["Ciphers/test/KeywordShiftedAlphabet.test.js"], + "mutants": [ + { + "name": "original defect restored (every character accepted)", + "file": "Ciphers/KeywordShiftedAlphabet.js", + "find": " return rest.indexOf(char) === -1\n", + "replace": " return true\n", + "tests": ["Ciphers/test/KeywordShiftedAlphabet.test.js"], + "must_fail": "smallest repeated keyword 'aa' is rejected" + } + ] +} diff --git a/work/R50-T002/versions.txt b/work/R50-T002/versions.txt new file mode 100644 index 0000000000..b405ff9cb4 --- /dev/null +++ b/work/R50-T002/versions.txt @@ -0,0 +1,5 @@ +python: 3.12.10 +node: v26.13.1 +npm: 11.20.0 +platform: macOS-27.2.1-arm64-arm-64bit +vitest: vitest/1.2.1 darwin-arm64 node-v26.13.1 diff --git a/work/R50-T002/vitest-focused.json b/work/R50-T002/vitest-focused.json new file mode 100644 index 0000000000..1a23fcc3ac --- /dev/null +++ b/work/R50-T002/vitest-focused.json @@ -0,0 +1,44 @@ +{ + "command": "node_modules/.bin/vitest run Ciphers/test/KeywordShiftedAlphabet.test.js --reporter=json --outputFile=work/R50-T002/vitest-focused.raw.json", + "numTotalTests": 9, + "numPassedTests": 9, + "numFailedTests": 0, + "tests": [ + { + "name": " Hello world! === decrypt(encrypt(Hello world!))", + "status": "passed" + }, + { + "name": " The Algorithms === decrypt(encrypt(The Algorithms))", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries valid side smallest valid keyword 'a' is accepted", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries valid side ordinary keyword 'keyword' is accepted", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries valid side largest valid keyword uses all 26 letters exactly once", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries invalid side smallest repeated keyword 'aa' is rejected", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries invalid side ordinary repeated keyword 'hello' is rejected", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries invalid side a 27th letter must repeat one of the 26 and is rejected", + "status": "passed" + }, + { + "name": " checkKeywordValidity boundaries invalid side empty keyword is rejected by checkInputs before validity", + "status": "passed" + } + ] +}