Compare commits

...
3 changed files with 398 additions and 0 deletions

No files matched your search

+261
View File
@@ -0,0 +1,261 @@
---
description: Investigate top flaky tests from the owncloud/ocis weekly pipeline report
argument-hint: "[workflow-run-url-or-local-json-path]"
allowed-tools: [Bash, Read, Glob, Grep, WebFetch, Agent]
---
Investigate flaky tests from the owncloud/ocis weekly pipeline CI report.
The argument (if provided) is: $ARGUMENTS
## Phase 1 – Fetch CI failure data
The weekly pipeline report workflow (`weekly_pipeline_report.yml`) runs a Go tool that emits a
JSON summary directly to the job log. There are no artifacts — the data is in the log.
**Step 1a – resolve the run ID.**
If $ARGUMENTS is a GitHub run URL (e.g. `https://github.com/owncloud/ocis/actions/runs/12345`),
extract the numeric run ID from the URL.
If $ARGUMENTS is a local file path, read it directly with the Read tool and skip to Phase 2.
If $ARGUMENTS is empty, fetch the most recent completed run:
```bash
gh api "repos/owncloud/ocis/actions/workflows/weekly_pipeline_report.yml/runs?per_page=5&status=completed" \
--jq '.workflow_runs[0] | {id, conclusion, created_at, html_url}' 2>/dev/null
```
**Step 1b – get the "Generate Pipeline Report" job ID for that run:**
```bash
gh api "repos/owncloud/ocis/actions/runs/RUN_ID/jobs" \
--jq '.jobs[] | select(.name == "Generate Pipeline Report") | {id, conclusion}' 2>/dev/null
```
**Step 1c – download the job log and extract the JSON report:**
The log ends with a JSON block starting at `{` after the line `Result: N failed / M total`.
Save the raw log then use Python to extract the JSON reliably:
```bash
gh api "repos/owncloud/ocis/actions/jobs/JOB_ID/logs" 2>/dev/null \
> /tmp/ocis_raw.log
python3 - <<'EOF'
import re, json, sys
raw = open('/tmp/ocis_raw.log').readlines()
# Find the "Result:" line
start = next((i for i, l in enumerate(raw) if 'Result:' in l), None)
if start is None:
print("ERROR: Result line not found", file=sys.stderr); sys.exit(1)
# Strip timestamps, fix secret redactions
lines = []
for l in raw[start+1:]:
l = re.sub(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z ', '', l)
lines.append(l)
text = ''.join(lines)
text = text.replace('***"', '[REDACTED]')
# raw_decode stops at end of valid JSON, ignoring trailing log lines
data, _ = json.JSONDecoder().raw_decode(text)
with open('/tmp/ocis_report.json', 'w') as f:
json.dump(data, f, indent=2)
print(f"OK: {len(data.get('count', []))} count entries, {len(data.get('pipelines', []))} pipelines")
EOF
```
If the API call fails or the Python script exits with an error, ask the user:
> "I couldn't fetch the CI report automatically. Please provide either:
> - A local path to the report JSON file
> - The URL of a specific GitHub Actions run (e.g. `https://github.com/owncloud/ocis/actions/runs/12345`)
> - The raw JSON pasted directly"
Once you have the JSON (either from the log or from the user), proceed to Phase 2.
**Step 1d – extract failure logs for the top-ranked steps:**
After `/tmp/ocis_report.json` is written, extract the `logs` field for each failing step entry
from the `pipelines` array and save them to `/tmp/ocis_step_logs.json`:
```bash
python3 - <<'EOF'
import json, sys
report = json.load(open('/tmp/ocis_report.json'))
count = report.get('count', [])
# Build a lookup: (stage_name, step_name) -> logs
logs_by_key = {}
for pipeline in report.get('pipelines', []):
for stage in pipeline.get('pipeline_info', {}).get('pipeline_stages', []):
for step in stage.get('steps', []):
if step.get('status') == 'failure':
key = (step.get('stage_name', ''), step.get('step_name', ''))
logs_by_key[key] = step.get('logs', '')
# Attach logs to top-5 count entries (excluding CI plumbing — same filter applied in Phase 2)
EXCLUDE = {'scan-result-cache', 'codacy', 'upload', 'publish', 'tarball',
'output', 'diff', 'clone', 'checkout', 'generate'}
def is_test_step(name):
n = name.lower()
if any(n.startswith(e) for e in EXCLUDE): return False
return any(k in n for k in ('test', 'e2e', 'api', 'cli'))
test_entries = [e for e in count if is_test_step(e.get('step_name', ''))]
test_entries.sort(key=lambda e: e.get('count', 0), reverse=True)
top5 = test_entries[:5]
result = []
for e in top5:
key = (e.get('stage_name', ''), e.get('step_name', ''))
result.append({
'stage_name': e['stage_name'],
'step_name': e['step_name'],
'count': e['count'],
'logs': logs_by_key.get(key, ''),
})
with open('/tmp/ocis_step_logs.json', 'w') as f:
json.dump(result, f, indent=2)
for i, r in enumerate(result, 1):
preview = (r['logs'] or '(no logs)')[:120].replace('\n', ' ')
print(f" {i}. [{r['count']}x] {r['stage_name']} / {r['step_name']}")
print(f" {preview}")
EOF
```
The output of this script provides the per-step log previews shown in the Phase 2 triage table,
and the full `logs` content is passed verbatim to each Phase 3 deep-dive agent.
## Phase 2 – Triage: rank top 5
The JSON has a `count` array of objects: `{stage_name, step_name, count}`.
**Exclude** these step names — they are CI plumbing, not test failures:
- `scan-result-cache`, `coverage-cache-*`, `restore_*`, `sync-from-cache`
- `codacy`, `upload`, `publish`, `tarball`, `output`, `diff`
- `clone`, `checkout`, `generate`, `build*`, `lint*`, `docs-*`
- `wait-for-*`, `health-check-*`, `restore-*`, `unzip-*`
- Any step whose name does not involve running actual tests
**Keep** entries whose step name contains: `run-api-tests`, `localApiTests-*`, `e2e-tests`,
`cli-tests`, `unit-tests`, `test`.
Sort the kept entries by `count` descending, take top 5.
Print a ranked table:
```
Rank | Failures | Stage / Step
-----|----------|--------------------------------------
1 | N | stage-name / step-name
2 | N | ...
...
```
Also print the overall summary line:
> `N failed / M total commits (P%) in the past 14 days`
Then ask the user:
> "Which of the top 5 should I investigate? Enter one or more numbers (e.g. `1` or `1,3,5`), or `all` for all five."
Wait for the user's selection before proceeding.
## Phase 3 – Deep-dive per selected offender
For each selected offender, launch a parallel Explore agent (one Agent call per offender).
Run all selected offenders in parallel.
Each agent receives:
- `stage_name` and `step_name`
- The full `logs` field extracted in Step 1d (Behat output: scenario title, feature file path,
failing step text, and assertion error)
Because the failure log is already known, the agent must **not** search for it from scratch.
Instead:
1. **Parse the provided failure log** to extract:
- The exact `Scenario:` title
- The feature file path and line number (already in the log)
- The failing Gherkin step text
- The assertion error / exception message
2. **Find the step definition** implementing the failing Gherkin step:
- Search `tests/acceptance/features/bootstrap/` for the PHP file and method matching the step.
- Note `file:line` for the matching step method.
3. **Find the Go server handler** invoked by that step:
- Trace the HTTP call (WebDAV, Graph API, CS3 gRPC) from the step definition to the Go backend.
- Search `services/` for the relevant service handler.
- Search `vendor/github.com/cs3org/reva/` for lower-level handlers.
- Note `file:line` and function name.
4. **Identify the flakiness mechanism**. Classify as one of:
- `timing` — test doesn't wait long enough for an async operation
- `race` — concurrent access without synchronization
- `ordering` — assumes deterministic result ordering
- `stale-cache` — reads from an index/cache before it's updated
- `resource-leak` — leftover state from a previous test
- `env-dep` — depends on external service availability or network
- `other` — describe specifically
5. **Return a structured result:**
```
STAGE: <stage-name>
STEP: <step-name>
SCENARIO: <full scenario title or "unknown — suite-level failure">
FEATURE_FILE: <path>:<line>
STEP_DEFINITION: <path>:<line> — <step text>
GO_HANDLER: <path>:<line> — <function name>
MECHANISM: <classification>
FAILURE_ASSERTION: <exact assert/error from logs if available>
EVIDENCE: <1-3 sentences describing what you found in the code>
```
## Phase 4 – Synthesize
For each investigated offender, produce a report section:
### [Rank]. `<Stage / Step>`
**Root cause** (one sentence): ...
**Evidence**
| What | Where | Detail |
|------|-------|--------|
| Failing assertion | `file:line` | exact error text |
| Step definition | `file:line` | step text |
| Server handler | `file:line` | function name |
**5-Why analysis**
1. Why did the test fail? — ...
2. Why did that condition occur? — ...
3. Why isn't that condition prevented? — ...
4. Why wasn't this caught earlier? — ...
5. Why does this recur? — ...
**Fix options** (least to most invasive)
1. *Test-side*: ...
2. *Test-side (alternative)*: ...
3. *Server-side*: ...
**Recommended fix**: Option N — rationale in one sentence.
---
## Phase 5 – Output
Print the full synthesized report for all investigated offenders.
Then ask the user:
> "Should I write this report to a markdown file? If yes, provide a filename or I'll use `flaky-test-report-YYYY-MM-DD.md`."
If the user confirms, write the report to the specified (or default) filename in the current directory.
@@ -0,0 +1,109 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Martin <github@diemattels.at>, 2026
# Miha Podobnik, 2026
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: EMAIL\n"
"POT-Creation-Date: 2026-03-24 00:06+0000\n"
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
"Last-Translator: Miha Podobnik, 2026\n"
"Language-Team: Slovenian (https://app.transifex.com/owncloud-org/teams/6149/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"
#: pkg/service/response.go:44
msgid "description"
msgstr "opis"
#: pkg/service/response.go:43
msgid "display name"
msgstr "prikazno ime"
#: pkg/service/response.go:42
msgid "expiration date"
msgstr "datum poteka"
#: pkg/service/response.go:41
msgid "password"
msgstr "geslo"
#: pkg/service/response.go:40
msgid "permission"
msgstr "dovoljenje"
#: pkg/service/response.go:45
msgid "shared-with-me"
msgstr "deljeno-z-mano"
#: pkg/service/response.go:39
msgid "some field"
msgstr "neko polje"
#: pkg/service/response.go:26
msgid "{resource} was downloaded via public link {token}"
msgstr "{resource} je bil prenesen prek javne povezave {token}"
#: pkg/service/response.go:24
msgid "{user} added {resource} to {folder}"
msgstr "{user} je dodal {resource} v {folder}"
#: pkg/service/response.go:36
msgid "{user} added {sharee} as member of {space}"
msgstr "{user} je dodal {sharee} kot član {space}"
#: pkg/service/response.go:27
msgid "{user} deleted {resource} from {folder}"
msgstr "{user} je izbrisal {resource} iz {folder}"
#: pkg/service/response.go:28
msgid "{user} moved {resource} to {folder}"
msgstr "{user} je premaknil {resource} v {folder}"
#: pkg/service/response.go:35
msgid "{user} removed link to {resource}"
msgstr "{user} je odstranil povezavo do {resource}"
#: pkg/service/response.go:32
msgid "{user} removed {sharee} from {resource}"
msgstr "{user} je odstranil uporabnika {sharee} iz {resource}"
#: pkg/service/response.go:37
msgid "{user} removed {sharee} from {space}"
msgstr "{user} je odstranil uporabnika {sharee} iz {space}"
#: pkg/service/response.go:29
msgid "{user} renamed {oldResource} to {resource}"
msgstr "{user} je preimenoval/a {oldResource} v {resource}"
#: pkg/service/response.go:33
msgid "{user} shared {resource} via link"
msgstr "{user} je omogočil souporabo {resource} prek povezave"
#: pkg/service/response.go:30
msgid "{user} shared {resource} with {sharee}"
msgstr "Uporabnik {user} je omogočil souporabo {resource} z {sharee}"
#: pkg/service/response.go:34
msgid "{user} updated {field} for a link {token} on {resource}"
msgstr ""
"Uporabnik {user} je posodobil polje {field} za povezavo {token} na viru "
"{resource}"
#: pkg/service/response.go:31
msgid "{user} updated {field} for the {resource}"
msgstr "{user} je preimenoval/a {oldResource} v {resource}"
#: pkg/service/response.go:25
msgid "{user} updated {resource} in {folder}"
msgstr "Uporabnik {user} je posodobil {resource} v {folder}"
+28
View File
@@ -190,6 +190,34 @@ make test-acceptance-api
make test-acceptance-api
```
### Run OCM tests
For running OCM test suite on k8s, we need to deploy a federation ocis server
in a separate namespace on the same cluster, alongside the ocis server:
1. Check if setup [step 3](#deploy-ocis-in-k8s) is done correctly. (`ENABLE_OCM=true`)
2. Prepare Charts for federation oCIS
```bash
OCM=true make prepare-charts
```
3. Deploy federation oCIS
```bash
OCM=true make deploy-ocis
```
4. Run the tests
```bash
TEST_SERVER_URL=https://ocis-server \
TEST_SERVER_FED_URL=https://federation-ocis-server \
K8S=true \
BEHAT_FEATURE=<test-suites-path>/apiOcm/share.feature \
make test-acceptance-api
```
## Cleanup the Setup
To delete the cluster and all the setup resources, run the following command: