kwikqa 0.2.4 → 0.3.0-rc.1

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.
Files changed (3) hide show
  1. package/README.md +155 -10
  2. package/dist/kwikqa.mjs +122 -102
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -182,8 +182,8 @@ WebdriverIO wherever your package manager installed it inside the repository, in
182
182
  | `npx kwikqa analyze --capture` | First re-run the failing tests so every failure has full evidence. Playwright runs with full tracing; with Playwright 1.59+ and [Playwright CLI](https://www.npmjs.com/package/@playwright/cli) installed, it also pauses locator failures at the failing line and asks Playwright for locators of the closest elements (`--no-probe` skips this). Cypress and WebdriverIO re-run the failing specs with your own config plus KwikQA's reporter and failure capture, which records each failed attempt's DOM, command log, console, and network. Asks before running anything; `--yes` approves in CI. |
183
183
  | `npx kwikqa analyze --html` | Also write the [failure report](#failure-report), `kwikqa-report.html`; `--output <path>` writes it elsewhere. |
184
184
  | `npx kwikqa report` | Write the failure report of the latest analysis without analyzing again or sending anything. `--run <id>` picks an earlier run under `.kwikqa/runs/`; `--output <path>` picks the file. |
185
- | `npx kwikqa ci` | In a CI job: analyze as `analyze --yes --html` does, then publish a summary. On GitHub Actions that is the job summary and one pull-request comment, on Azure Pipelines a build summary and one pull-request thread, and on GitLab CI/CD the job's log and one merge-request note; with your webhooks, also a Slack or Teams message. See [CI](#ci). Without a KwikQA token it analyzes locally. It takes `--report`, `--framework`, `--local`, `--no-changes`, and `--output` as `analyze` does, and `--notify always` to post to chat after every run, not only failed ones. |
186
- | `npx kwikqa fix` | Propose a repair for a test-side cause, show the diff and validation commands, and apply it if you approve. First it offers to re-run the failing tests once: a test that passes now is flaky, so KwikQA reports it and requests no repair. It starts with the failure group whose test-side diagnosis is strongest; if the model declines, or its proposal fails KwikQA's checks, it asks about the next such group, at most three, each with its own preview. One `fix` counts as one fix however many groups it tries. `--group <n>` repairs only group n, as `analyze` numbered it. `--propose-only` stops after the proposal. |
185
+ | `npx kwikqa ci` | In a CI job: analyze as `analyze --yes --html` does, then publish a summary. On GitHub Actions that is the job summary and one pull-request comment, on Azure Pipelines a build summary and one pull-request thread, on GitLab CI/CD the job's log and one merge-request note, and on Jenkins the console log and one comment on a GitHub or GitLab pull request; with your webhooks, also a Slack or Teams message. See [CI](#ci). Without a KwikQA token it analyzes locally. It takes `--report`, `--framework`, `--local`, `--no-changes`, and `--output` as `analyze` does, and `--notify always` to post to chat after every run, not only failed ones. |
186
+ | `npx kwikqa fix` | Propose a repair for a test-side cause, show the diff and validation commands, and apply it if you approve. First it offers to re-run the failing tests once: a test that passes now is flaky, so KwikQA reports it and requests no repair. It starts with the failure group whose test-side diagnosis is strongest; if the model declines, or its proposal fails KwikQA's checks, it asks about the next such group, at most three, each with its own preview. One `fix` counts as one fix however many groups it tries. `--group <n>` repairs only group n, as `analyze` numbered it. `--propose-only` stops after the proposal. In GitHub Actions, Azure Pipelines, and GitLab CI/CD, a committed `ci.fix` policy lets it run without a terminal and open a draft pull request; see [Fix pull requests](#fix-pull-requests). |
187
187
  | `npx kwikqa validate` | Run the approved validation. The repaired test must pass three times in a row, with retries off. Passing keeps the patch; failing rolls it back. When other tests failed with the same cause, it then offers to re-run them once and names any that still fail, so you can run `fix` again for them; the patch stays either way. |
188
188
  | `npx kwikqa fix --retry` | After a failed validation, re-diagnose from the new evidence and propose one revised patch. |
189
189
  | `npx kwikqa status` | Show your plan, team, and this month's usage. |
@@ -302,8 +302,10 @@ Run records, transaction journals, captures, and validation output stay on your
302
302
 
303
303
  ## CI
304
304
 
305
- `analyze` and `ci` run unattended; `fix` doesn't, because applying a patch always needs a person.
306
- Create a CI token at https://kwikqa.com/dashboard/account/ and store it as the secret
305
+ `analyze` and `ci` run unattended. `fix` doesn't, because applying a patch needs a person, except as
306
+ a draft pull request in GitHub Actions, Azure Pipelines, or GitLab CI/CD, where a person approves by
307
+ merging: see
308
+ [Fix pull requests](#fix-pull-requests). Create a CI token at https://kwikqa.com/dashboard/account/ and store it as the secret
307
309
  `KWIKQA_TOKEN`. Running KwikQA with it approves its diagnosis requests, and each request's preview
308
310
  is printed to the job's log.
309
311
 
@@ -348,6 +350,71 @@ steps:
348
350
  in the log and skipped; the exit code is the analysis's. Without a KwikQA token, or past your
349
351
  plan's limit, the run is analyzed locally and the summary says why it wasn't diagnosed.
350
352
 
353
+ ### Fix pull requests
354
+
355
+ In GitHub Actions, `kwikqa fix` can repair a failure on the runner and open the repair as a draft
356
+ pull request. Nothing lands until a person reviews and merges it. Opt in by committing a policy in
357
+ `kwikqa.config.json`:
358
+
359
+ ```json
360
+ {
361
+ "ci": { "fix": { "pullRequests": "draft", "retry": false } }
362
+ }
363
+ ```
364
+
365
+ Then run it after your tests, in the same job:
366
+
367
+ ```yaml
368
+ permissions:
369
+ contents: write # for the fix branch
370
+ pull-requests: write # for the comment and the fix pull request
371
+ steps:
372
+ - uses: actions/checkout@v7
373
+ - run: npx playwright test
374
+ - if: failure()
375
+ run: npx kwikqa ci
376
+ env:
377
+ KWIKQA_TOKEN: ${{ secrets.KWIKQA_TOKEN }}
378
+ GITHUB_TOKEN: ${{ github.token }}
379
+ - if: failure()
380
+ run: npx kwikqa fix
381
+ env:
382
+ KWIKQA_TOKEN: ${{ secrets.KWIKQA_TOKEN }}
383
+ GITHUB_TOKEN: ${{ github.token }}
384
+ ```
385
+
386
+ Also turn on "Allow GitHub Actions to create and approve pull requests" in the repository's or
387
+ organization's Actions settings.
388
+
389
+ - **What it does.** It re-runs the failing tests once to confirm the failure, asks for one repair,
390
+ and applies it to the runner's checkout. The repaired test must pass three times in a row, with
391
+ retries off. A failure is rolled back, and retried once only with `"retry": true`. One CI fix
392
+ counts as one fix, and it reuses the diagnosis `kwikqa ci` made.
393
+ - **The pull request.** A draft labeled `kwikqa`, from a new branch `kwikqa/fix-<id>` named after
394
+ the failure group. For a pull request's run, it goes into that pull request's branch, as a change
395
+ to the change; for any other branch's run, such as a nightly suite on `main`, into that branch.
396
+ Its description gives the diagnosis, the repair's intent, its validation, and which models were
397
+ asked. KwikQA builds its commit through GitHub's API, so the runner's git writes nothing, and it
398
+ never moves a branch it didn't create.
399
+ - **Only under the committed policy.** The policy counts only if `kwikqa.config.json` is exactly as
400
+ committed, and only for the runner's checkout, inside `GITHUB_WORKSPACE`. Each request, re-run,
401
+ and patch is printed in the log with what approved it.
402
+ - **One per failure group.** While a group's fix pull request is open, a later run of the same
403
+ failure asks for no repair and costs no fix; it updates one note on that pull request instead. A
404
+ `kwikqa/fix-` branch left after a closed pull request also holds the group back until you delete
405
+ it.
406
+ - **When it can't open one.** A fork's pull request, a run on a tag, and a job without
407
+ `GITHUB_TOKEN` are refused before any request, so they cost nothing. For a fork, the job summary
408
+ says what a maintainer can run. If the pull request's branch has changed the repaired file since
409
+ the run, nothing is committed.
410
+ - **Checks on the fix pull request.** GitHub doesn't start workflows for a pull request the job's
411
+ `GITHUB_TOKEN` opens; close and reopen it, or push to it, to run them. To have them start by
412
+ themselves, give `kwikqa fix` a token from your own GitHub App (`actions/create-github-app-token`)
413
+ as `GITHUB_TOKEN`.
414
+ - **Plans.** GitHub Free has no draft pull requests in private repositories, and KwikQA opens only
415
+ drafts. Azure Pipelines and GitLab CI/CD work the same way, as below; Jenkins still needs a
416
+ terminal for `fix`.
417
+
351
418
  ### Azure Pipelines
352
419
 
353
420
  ```yaml
@@ -379,6 +446,22 @@ and `System.AccessToken`, only through the step's `env`.
379
446
  only.
380
447
  - **Forks.** A fork's build gets no secrets unless the pipeline allows it. KwikQA analyzes it
381
448
  locally and skips the thread.
449
+ - **Fix pull requests.** With a committed `ci.fix` policy, as in
450
+ [Fix pull requests](#fix-pull-requests), add a `kwikqa fix` step after `kwikqa ci`:
451
+
452
+ ```yaml
453
+ - script: npx kwikqa fix
454
+ condition: failed()
455
+ env:
456
+ KWIKQA_TOKEN: $(KWIKQA_TOKEN)
457
+ SYSTEM_ACCESSTOKEN: $(System.AccessToken)
458
+ ```
459
+
460
+ It repairs and validates on the agent, then opens a draft pull request on Azure Repos: for a pull
461
+ request's build, into its source branch, built on its source commit; for any other branch, into
462
+ that branch. The build service needs "Contribute", "Create branch", and "Contribute to pull
463
+ requests" on the repository. A repository on GitHub or Bitbucket, and a fork's build, are refused
464
+ before any request.
382
465
 
383
466
  ### GitLab CI/CD
384
467
 
@@ -399,16 +482,78 @@ The `exit 1` keeps the job failed: KwikQA exits with the analysis's code, which
399
482
 
400
483
  - **Variables.** Add `KWIKQA_TOKEN` and `GITLAB_TOKEN` under Settings → CI/CD → Variables. Mark
401
484
  them **masked**, and leave **protected** off, or a feature branch's pipeline won't get them.
402
- - **The token.** `CI_JOB_TOKEN` can't write notes, so `GITLAB_TOKEN` is a token with the `api`
403
- scope and at least the Reporter role. Use a project or group access token (Premium or Ultimate on
404
- GitLab.com, any tier when self-managed), or a personal access token, ideally a dedicated user's.
405
- The note is posted as that token's user.
485
+ - **The token.** `CI_JOB_TOKEN` can't write notes, so `GITLAB_TOKEN` is a token of your own, with
486
+ at least the Reporter role. The note is posted as that token's user.
487
+ - A fine-grained personal access token needs only your project, with Work Item read, create, and
488
+ update. GitLab's merge-request notes API comes under Work Item. Make it a dedicated user's if
489
+ you can.
490
+ - Otherwise, a token with the `api` scope: a legacy personal access token, or a project or group
491
+ access token (Premium or Ultimate on GitLab.com, any tier when self-managed).
406
492
  - **Merge-request note.** The summary is printed in the job's log and posted as one note on the
407
493
  merge request. A re-run of the same job updates it. A merge request pipeline names its merge
408
494
  request. A branch pipeline gets a note when its branch has exactly one open merge request in the
409
495
  project.
410
496
  - **Forks.** A fork's merge request pipeline runs in the fork, without your project's variables.
411
497
  KwikQA analyzes it locally and skips the note.
498
+ - **Fix merge requests.** With a committed `ci.fix` policy, as in
499
+ [Fix pull requests](#fix-pull-requests), run `kwikqa fix` after `kwikqa ci`:
500
+
501
+ ```yaml
502
+ - npx playwright test || { npx kwikqa ci; npx kwikqa fix; exit 1; }
503
+ ```
504
+
505
+ It repairs and validates in the job, then opens a draft merge request: for a merge request's
506
+ pipeline, into its source branch, built on its head commit; for a branch pipeline, into that
507
+ branch. The merge request is labeled `kwikqa` and removes its branch when merged. `GITLAB_TOKEN`
508
+ needs the `api` scope and at least the Developer role, to push the fix branch; a fine-grained
509
+ token isn't verified for this yet. A merge request from a fork, and a tag's pipeline, are refused
510
+ before any request.
511
+
512
+ ### Jenkins
513
+
514
+ In a Pipeline, run `kwikqa ci` when the tests fail, with its tokens bound only around it. The agent
515
+ needs Node.js 20.11 or later.
516
+
517
+ ```groovy
518
+ stage('e2e') {
519
+ steps {
520
+ sh 'npm ci'
521
+ sh 'npx playwright test'
522
+ }
523
+ post {
524
+ failure {
525
+ withCredentials([
526
+ string(credentialsId: 'kwikqa-token', variable: 'KWIKQA_TOKEN'),
527
+ string(credentialsId: 'github-token', variable: 'GITHUB_TOKEN'),
528
+ ]) {
529
+ sh 'npx kwikqa ci'
530
+ }
531
+ archiveArtifacts artifacts: 'kwikqa-report.html', allowEmptyArchive: true
532
+ }
533
+ }
534
+ }
535
+ ```
536
+
537
+ - **Summary.** It's printed in the build's console log, with a link to the build, where the
538
+ archived report is.
539
+ - **Pull-request comment.** In a multibranch project, a pull request's build knows its pull
540
+ request from the branch source. KwikQA comments on it through its host, and a rebuild updates
541
+ the comment:
542
+ - GitHub, including GitHub Enterprise, with `GITHUB_TOKEN`: a fine-grained token with Pull
543
+ requests read and write on the repository, or a classic token with the `repo` scope. A GitHub
544
+ App credential works too, bound with `usernamePassword(credentialsId: 'github-app',
545
+ usernameVariable: 'GITHUB_APP', passwordVariable: 'GITHUB_TOKEN')`. Its token lasts an hour, so
546
+ bind it around `kwikqa ci`, as above.
547
+ - GitLab, with `GITLAB_TOKEN`, a token as in [GitLab CI/CD](#gitlab-cicd).
548
+ - Bitbucket and other hosts get no comment yet.
549
+ - **Forks.** Jenkins gives a fork's pull request build the credentials its Jenkinsfile binds, and
550
+ that build runs the fork's code, its `package.json` included. If you build pull requests from
551
+ forks you don't trust, don't bind tokens in their builds. The branch source's trust setting only
552
+ decides whose Jenkinsfile runs.
553
+ - **The report.** Jenkins serves an archived page with its script and styles blocked, and the report
554
+ stays readable that way. For its styles and filters too, set a Resource Root URL on another host
555
+ name, under Manage Jenkins → System → "Serve resource files from another domain". Don't loosen
556
+ Jenkins' Content-Security-Policy instead.
412
557
 
413
558
  ### Slack and Microsoft Teams
414
559
 
@@ -429,8 +574,8 @@ a wider audience than a build log. KwikQA posts only when tests failed, unless y
429
574
 
430
575
  ### Other CI systems
431
576
 
432
- On Jenkins and other CI systems, `npx kwikqa ci` writes the report and posts to Slack and Teams,
433
- but writes no summary or comment yet:
577
+ On other CI systems, `npx kwikqa ci` writes the report and posts to Slack and Teams, but writes no
578
+ summary or comment yet:
434
579
 
435
580
  ```sh
436
581
  npx playwright test || { npx kwikqa ci; exit 1; }