@mrevanzak/witness 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mochamad Revanza Kurniawan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # Witness
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Witness checks a code change the way a QA tester would, then hands you the evidence. Point it at a branch or a pull request. It boots the app in a fresh Linux desktop, works out what the change should do, uses the app with a mouse and keyboard, and records everything. You get a verdict per criterion, stills, a short edited video, and a report you can drop into the PR or share as a link.
4
+
5
+ It never edits code and it doesn't take the coding agent's word for anything. It only reports what it saw.
6
+
7
+ ## Install
8
+
9
+ You need Docker (OrbStack works well on macOS), Node 22.18 or newer, and ffmpeg.
10
+
11
+ ```bash
12
+ npm install -g @mrevanzak/witness
13
+ witness image # builds the computer image once: Xvfb, Chromium, ffmpeg, control server
14
+ ```
15
+
16
+ ## Use
17
+
18
+ ```bash
19
+ witness init --repo ../my-app # drafts witness.yaml: how to boot the app
20
+ witness run --repo ../my-app --boot-only # proves the app boots
21
+ witness run --repo ../my-app --ref feat/x --base main --task "Empty todo titles are rejected" --session
22
+ witness act … # drive the session, one recorded action at a time
23
+ witness render .witness/runs/<run-id> # polished.mp4 + preview.gif
24
+ witness report .witness/runs/<run-id> # report.md, ready for the PR description
25
+ ```
26
+
27
+ Runs are recorded under `.witness/runs/` at the root of the git repo you run `witness` from. Exit codes: 0 pass, 1 fail, 2 blocked, 3 usage error.
28
+
29
+ `witness --help` lists every command. The full guide (the three ways to drive a run, `witness.yaml`, before and after, publishing evidence, the Claude Code skill) is in the [repository](https://github.com/mrevanzak/witness#readme).
30
+
31
+ ## License
32
+
33
+ MIT
@@ -0,0 +1,148 @@
1
+ "use strict"
2
+ // Witness's Playwright reporter, staged into the computer next to the spec. It
3
+ // writes one JSON line per test, step and result to `out`; the orchestrator turns
4
+ // them into criteria, steps, stills and a verdict. Only tests of `project` count
5
+ // (setup projects it depends on still run, but are not criteria).
6
+ const { execFileSync } = require("node:child_process")
7
+ const fs = require("node:fs")
8
+ const path = require("node:path")
9
+
10
+ // Click points from a trace.zip: each input event's point, timed by its call's start.
11
+ const TRACE_POINTS = `
12
+ import json, sys, zipfile
13
+ z = zipfile.ZipFile(sys.argv[1])
14
+ out = []
15
+ for name in z.namelist():
16
+ if not name.endswith(".trace"):
17
+ continue
18
+ wall = mono = None
19
+ starts = {}
20
+ for line in z.read(name).decode("utf-8", "replace").splitlines():
21
+ try:
22
+ e = json.loads(line)
23
+ except Exception:
24
+ continue
25
+ t = e.get("type")
26
+ if t == "context-options":
27
+ wall, mono = e.get("wallTime"), e.get("monotonicTime")
28
+ elif t == "before":
29
+ starts[e.get("callId")] = e.get("startTime")
30
+ elif t == "input" and e.get("point") and wall is not None and mono is not None:
31
+ s = starts.get(e.get("callId"))
32
+ if s is not None:
33
+ out.append({"at": wall + (s - mono), "x": e["point"]["x"], "y": e["point"]["y"]})
34
+ print(json.dumps(out))
35
+ `
36
+
37
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: strips ANSI colours from error messages
38
+ const ANSI = /\u001b\[[0-9;]*m/g
39
+ const slug = (s) =>
40
+ s
41
+ .toLowerCase()
42
+ .replace(/[^a-z0-9]+/g, "-")
43
+ .replace(/^-|-$/g, "")
44
+ .slice(0, 40) || "still"
45
+
46
+ /** Title of the innermost test.step around `step`, if any. */
47
+ const parentStep = (step) => {
48
+ for (let p = step.parent; p; p = p.parent) {
49
+ if (p.category === "test.step") {
50
+ return p.title
51
+ }
52
+ }
53
+ }
54
+
55
+ class WitnessReporter {
56
+ constructor(options) {
57
+ this.out = options.out
58
+ this.project = options.project
59
+ this.dir = path.dirname(this.out)
60
+ this.n = 0
61
+ fs.mkdirSync(path.join(this.dir, "att"), { recursive: true })
62
+ fs.writeFileSync(this.out, "")
63
+ }
64
+
65
+ write(event) {
66
+ fs.appendFileSync(this.out, `${JSON.stringify(event)}\n`)
67
+ }
68
+
69
+ ours(test) {
70
+ return !this.project || test.parent.project()?.name === this.project
71
+ }
72
+
73
+ onBegin(_config, suite) {
74
+ this.write({ total: suite.allTests().filter((t) => this.ours(t)).length, type: "begin" })
75
+ }
76
+
77
+ onTestBegin(test, result) {
78
+ if (this.ours(test)) {
79
+ this.write({ at: result.startTime.getTime(), id: test.id, tags: test.tags, title: test.title, type: "test" })
80
+ }
81
+ }
82
+
83
+ onStepBegin(test, _result, step) {
84
+ if (!this.ours(test)) {
85
+ return
86
+ }
87
+ if (step.category === "pw:api" || step.category === "test.step" || step.category.includes("attach")) {
88
+ this.write({
89
+ at: step.startTime.getTime(),
90
+ category: step.category,
91
+ id: test.id,
92
+ parent: parentStep(step),
93
+ title: step.title,
94
+ type: "step",
95
+ })
96
+ }
97
+ }
98
+
99
+ onTestEnd(test, result) {
100
+ if (!this.ours(test)) {
101
+ return
102
+ }
103
+ const attachments = []
104
+ let points = []
105
+ for (const a of result.attachments) {
106
+ if (a.name === "trace" && a.path) {
107
+ try {
108
+ points = JSON.parse(execFileSync("python3", ["-c", TRACE_POINTS, a.path], { encoding: "utf8" }))
109
+ } catch {
110
+ points = []
111
+ }
112
+ continue
113
+ }
114
+ if (!(a.contentType?.startsWith("image/") && (a.path || a.body))) {
115
+ continue
116
+ }
117
+ this.n += 1
118
+ const file = path.join("att", `${String(this.n).padStart(2, "0")}-${slug(a.name)}.png`)
119
+ if (a.path) {
120
+ fs.copyFileSync(a.path, path.join(this.dir, file))
121
+ } else {
122
+ fs.writeFileSync(path.join(this.dir, file), a.body)
123
+ }
124
+ attachments.push({ file, name: a.name })
125
+ }
126
+ this.write({
127
+ annotations: [...test.annotations, ...(result.annotations ?? [])],
128
+ at: result.startTime.getTime() + result.duration,
129
+ attachments,
130
+ error: (result.error?.message ?? "").replace(ANSI, ""),
131
+ id: test.id,
132
+ outcome: test.outcome(),
133
+ points,
134
+ status: result.status,
135
+ type: "end",
136
+ })
137
+ }
138
+
139
+ onEnd(result) {
140
+ this.write({ status: result.status, type: "done" })
141
+ }
142
+
143
+ printsToStdio() {
144
+ return false
145
+ }
146
+ }
147
+
148
+ module.exports = WitnessReporter