Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Improve issue version triage and remove title prefixes (#1217)
Ali Khokhard37b34b02fb7
diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.ymlindex 145078d8..5c891556 100644--- a/.github/ISSUE_TEMPLATE/bug-report.yml+++ b/.github/ISSUE_TEMPLATE/bug-report.yml@@ -1,6 +1,5 @@name: Bug reportdescription: Report something that is not working in Free Claude Code.-title: "[Bug]: "labels:- bugbody:@@ -8,8 +7,8 @@ body:id: fcc-versionattributes:label: FCC version- description: Run `fcc-server --version` and enter only the version number, such as `4.6.1`. If FCC did not install, enter `None`.- placeholder: "4.6.1 or None"+ description: Run `fcc-server --version` and include one version in `number.number.number` format. If FCC did not install, enter `None`.+ placeholder: "The version is 1.22.333, or None"validations:required: truediff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.ymlindex 7c1f331e..397f5afb 100644--- a/.github/ISSUE_TEMPLATE/feature-request.yml+++ b/.github/ISSUE_TEMPLATE/feature-request.yml@@ -1,6 +1,5 @@name: Feature requestdescription: Suggest an improvement to Free Claude Code.-title: "[Feature]: "labels:- enhancementbody:diff --git a/.github/workflows/validate-bug-report-version.yml b/.github/workflows/validate-bug-report-version.ymlindex a8eb7616..e1db5412 100644--- a/.github/workflows/validate-bug-report-version.yml+++ b/.github/workflows/validate-bug-report-version.yml@@ -6,9 +6,10 @@ on:concurrency:group: bug-report-version-${{ github.event.issue.number }}- cancel-in-progress: true+ cancel-in-progress: falsepermissions:+ contents: readissues: writejobs:@@ -21,60 +22,154 @@ jobs:uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0with:script: |- const issue = context.payload.issue;+ const repo = context.repo;+ const issue_number = context.payload.issue.number;+ const { data: issue } = await github.rest.issues.get({+ ...repo,+ issue_number,+ });const fieldPattern = "^### FCC version\\r?\\n+\\s*([^\\r\\n]+)";- const versionPattern = "^(?:(?:free-claude-code )?\\d+\\.\\d+\\.\\d+|None)$";+ const versionPattern = "(?:^|[^0-9A-Za-z_.])v?([0-9]+\\.[0-9]+\\.[0-9]+)(?![0-9A-Za-z_+-]|\\.[0-9A-Za-z_])";+ const projectVersionPattern = "^\\s*version\\s*=\\s*([\"'])([0-9]+\\.[0-9]+\\.[0-9]+)\\1\\s*(?:#.*)?$";const match = (issue.body || "").match(new RegExp(fieldPattern, "m"));- const version = match?.[1]?.trim() || "";- const valid = new RegExp(versionPattern).test(version);+ const fieldValue = match?.[1]?.trim() || "";+ const versionMatches = [...fieldValue.matchAll(new RegExp(versionPattern, "g"))];+ const reportedVersion = versionMatches.length === 1 ? versionMatches[0][1] : undefined;+ const valid = reportedVersion !== undefined || fieldValue === "None";const labelName = "needs-fcc-version";- const marker = "<!-- fcc-version-validator -->";+ const invalidMarker = "<!-- fcc-version-validator -->";+ const outdatedMarker = "<!-- fcc-version-outdated -->";const labels = new Set(issue.labels.map((label) => label.name));- const repo = context.repo;- const issue_number = issue.number;- if (valid) {- if (labels.has(labelName)) {- await github.rest.issues.removeLabel({+ const comments = await github.paginate(+ github.rest.issues.listComments,+ { ...repo, issue_number, per_page: 100 },+ );+ const managedComment = (marker) => comments.find(+ (comment) => comment.user?.login === "github-actions[bot]"+ && comment.body?.includes(marker),+ );+ const invalidComment = managedComment(invalidMarker);+ const outdatedComment = managedComment(outdatedMarker);++ const deleteManagedComment = async (comment) => {+ if (comment === undefined) return;+ await github.rest.issues.deleteComment({+ ...repo,+ comment_id: comment.id,+ });+ };++ const isOlderVersion = (reported, latest) => {+ const reportedParts = reported.split(".").map((part) => BigInt(part));+ const latestParts = latest.split(".").map((part) => BigInt(part));+ for (let index = 0; index < reportedParts.length; index += 1) {+ if (reportedParts[index] < latestParts[index]) return true;+ if (reportedParts[index] > latestParts[index]) return false;+ }+ return false;+ };++ const projectVersionFromToml = (pyproject) => {+ let inProjectSection = false;+ for (const line of pyproject.split(/\r?\n/)) {+ const stripped = line.trim();+ if (stripped === "[project]") {+ inProjectSection = true;+ continue;+ }+ if (inProjectSection && stripped.startsWith("[")) return undefined;+ if (!inProjectSection) continue;+ const projectVersion = line.match(new RegExp(projectVersionPattern));+ if (projectVersion !== null) return projectVersion[2];+ }+ return undefined;+ };++ if (!valid) {+ await deleteManagedComment(outdatedComment);+ if (!labels.has(labelName)) {+ try {+ await github.rest.issues.getLabel({ ...repo, name: labelName });+ } catch (error) {+ if (error.status !== 404) throw error;+ try {+ await github.rest.issues.createLabel({+ ...repo,+ name: labelName,+ color: "d4c5f9",+ description: "FCC version must contain number.number.number or be None",+ });+ } catch (createError) {+ if (createError.status !== 422) throw createError;+ }+ }+ await github.rest.issues.addLabels({+ ...repo,+ issue_number,+ labels: [labelName],+ });+ }+ if (invalidComment === undefined) {+ await github.rest.issues.createComment({...repo,issue_number,- name: labelName,+ body: `${invalidMarker}\nPlease edit **FCC version** so it contains one \`number.number.number\` value, such as \`1.22.333\`, or is exactly \`None\`. Run \`fcc-server --version\` to find the installed version.`,});}return;}- if (!labels.has(labelName)) {- try {- await github.rest.issues.getLabel({ ...repo, name: labelName });- } catch (error) {- if (error.status !== 404) throw error;- try {- await github.rest.issues.createLabel({- ...repo,- name: labelName,- color: "d4c5f9",- description: "FCC version must be number.number.number or None",- });- } catch (createError) {- if (createError.status !== 422) throw createError;- }- }- await github.rest.issues.addLabels({+ if (labels.has(labelName)) {+ await github.rest.issues.removeLabel({...repo,issue_number,- labels: [labelName],+ name: labelName,});}+ await deleteManagedComment(invalidComment);- const comments = await github.paginate(- github.rest.issues.listComments,- { ...repo, issue_number, per_page: 100 },- );- if (!comments.some((comment) => comment.body?.includes(marker))) {+ if (reportedVersion === undefined) {+ await deleteManagedComment(outdatedComment);+ return;+ }++ const defaultBranch = context.payload.repository.default_branch;+ const { data: versionFile } = await github.rest.repos.getContent({+ ...repo,+ path: "pyproject.toml",+ ref: defaultBranch,+ });+ if (+ Array.isArray(versionFile)+ || versionFile.type !== "file"+ || versionFile.encoding !== "base64"+ || !versionFile.content+ ) {+ throw new Error(`Could not read pyproject.toml from ${defaultBranch}`);+ }+ const pyproject = Buffer.from(versionFile.content, "base64").toString("utf8");+ const latestVersion = projectVersionFromToml(pyproject);+ if (latestVersion === undefined) {+ throw new Error(`Could not read the project version from ${defaultBranch}`);+ }++ if (!isOlderVersion(reportedVersion, latestVersion)) {+ await deleteManagedComment(outdatedComment);+ return;+ }++ const body = `${outdatedMarker}\nThis report uses FCC \`${reportedVersion}\`, while the current version on \`${defaultBranch}\` is \`${latestVersion}\`. Please [update FCC](${context.payload.repository.html_url}#install), restart FCC, and check whether the issue still occurs. The update may already contain the fix.`;+ if (outdatedComment === undefined) {await github.rest.issues.createComment({...repo,issue_number,- body: `${marker}\nPlease edit **FCC version** to contain only an exact \`number.number.number\` value, such as \`4.6.1\`, or \`None\`. Run \`fcc-server --version\` to find the installed version.`,+ body,+ });+ } else if (outdatedComment.body !== body) {+ await github.rest.issues.updateComment({+ ...repo,+ comment_id: outdatedComment.id,+ body,});}diff --git a/tests/contracts/test_issue_form_version_validation.py b/tests/contracts/test_issue_form_version_validation.pyindex 525a3616..4ac37c8c 100644--- a/tests/contracts/test_issue_form_version_validation.py+++ b/tests/contracts/test_issue_form_version_validation.py@@ -1,6 +1,11 @@import jsonimport re+import shutil+import subprocess+import textwrap+import tomllibfrom pathlib import Path+from typing import Anyimport pytest@@ -10,36 +15,75 @@ WORKFLOW = Path(".github/workflows/validate-bug-report-version.yml")def _workflow_pattern(name: str) -> str:workflow = WORKFLOW.read_text(encoding="utf-8")- match = re.search(rf"const {name} = (\"[^\"]+\");", workflow)+ match = re.search(rf'const {name} = ("(?:\\.|[^"\\])*");', workflow)assert match is not Nonereturn json.loads(match.group(1))-def test_bug_form_requests_an_exact_version_or_none() -> None:+def _reported_version(value: str) -> str | None:+ matches = re.findall(_workflow_pattern("versionPattern"), value)+ return matches[0] if len(matches) == 1 else None+++def _javascript_function(name: str) -> str:+ workflow = WORKFLOW.read_text(encoding="utf-8")+ match = re.search(+ rf"^ const {name} = .*?^ }};",+ workflow,+ flags=re.DOTALL | re.MULTILINE,+ )+ assert match is not None+ return textwrap.dedent(match.group(0))+++def _workflow_script() -> str:+ workflow = WORKFLOW.read_text(encoding="utf-8")+ marker = " script: |\n"+ _, separator, script = workflow.partition(marker)+ assert separator == marker+ return textwrap.dedent(script)+++def _run_javascript(script: str) -> Any:+ node = shutil.which("node")+ if node is None:+ pytest.skip("Node.js is required to execute the GitHub workflow contract")+ completed = subprocess.run(+ [node, "--input-type=module", "--eval", script],+ check=True,+ capture_output=True,+ text=True,+ )+ return json.loads(completed.stdout)+++def test_bug_form_requests_a_contained_version_or_none() -> None:form = BUG_FORM.read_text(encoding="utf-8")assert "Run `fcc-server --version`" in form- assert "enter only the version number" in form+ assert "include one version" in form+ assert "`number.number.number` format" in formassert "enter `None`" in form- assert 'placeholder: "4.6.1 or None"' in form+ assert 'placeholder: "The version is 1.22.333, or None"' in formassert "not installed" not in form- assert "free-claude-code" not in form@pytest.mark.parametrize(- "value",+ ("value", "expected"),[- "0.0.0",- "4.6.1",- "123.45.678",- "free-claude-code 0.0.0",- "free-claude-code 4.6.1",- "free-claude-code 123.45.678",- "None",+ ("0.0.0", "0.0.0"),+ ("1.22.333", "1.22.333"),+ ("The version is 1.22.333", "1.22.333"),+ ("free-claude-code 4.11.4", "4.11.4"),+ ("v123.45.678", "123.45.678"),+ ("Version 4.6.1.", "4.6.1"),],)-def test_version_pattern_accepts_supported_values(value: str) -> None:- assert re.fullmatch(_workflow_pattern("versionPattern"), value)+def test_version_pattern_extracts_a_contained_version(+ value: str,+ expected: str,+) -> None:+ assert _reported_version(value) == expected@pytest.mark.parametrize(@@ -49,17 +93,47 @@ def test_version_pattern_accepts_supported_values(value: str) -> None:"latest","4.6","4.6.1.2",- "v4.6.1",+ ".4.6.1","4.6.x","none","free-claude-code",- "free-claude-code v4.6.1","free-claude-code 4.6",- "free-claude-code 4.6.1 extra",+ "the version is 4.6.1.2",+ "upgraded from 4.6.1 to 4.11.4",+ "build4.6.1",+ "4.6.1-beta",+ "4.6.1+build",+ "4.6.1.x",],)def test_version_pattern_rejects_ambiguous_values(value: str) -> None:- assert re.fullmatch(_workflow_pattern("versionPattern"), value) is None+ assert _reported_version(value) is None+++def test_none_remains_an_exact_escape_hatch() -> None:+ workflow = WORKFLOW.read_text(encoding="utf-8")++ assert 'fieldValue === "None"' in workflow+ assert _reported_version("None") is None+ assert _reported_version("The version is None") is None+++def test_numeric_version_comparison_uses_all_three_components() -> None:+ function = _javascript_function("isOlderVersion")+ cases = [+ ["4.9.99", "4.10.0"],+ ["4.10.0", "4.10.0"],+ ["4.10.1", "4.10.0"],+ ["9007199254740993.0.0", "9007199254740994.0.0"],+ ]+ script = (+ f"{function}\n"+ f"const cases = {json.dumps(cases)};\n"+ "process.stdout.write(JSON.stringify("+ "cases.map(([reported, latest]) => isOlderVersion(reported, latest))));"+ )++ assert _run_javascript(script) == [True, False, False, True]def test_field_pattern_extracts_the_issue_form_value() -> None:@@ -88,4 +162,171 @@ def test_workflow_owns_one_idempotent_triage_state() -> None:assert "github.rest.issues.createLabel" in workflowassert "github.rest.issues.addLabels" in workflowassert "github.rest.issues.removeLabel" in workflow- assert "comments.some" in workflow+ assert "comments.find" in workflow+++def test_workflow_reads_and_compares_the_default_branch_version() -> None:+ workflow = WORKFLOW.read_text(encoding="utf-8")+ pyproject = Path("pyproject.toml").read_text(encoding="utf-8")+ expected = tomllib.loads(pyproject)["project"]["version"]+ project_pattern = _workflow_pattern("projectVersionPattern")+ function = _javascript_function("projectVersionFromToml")+ scoped_project = (+ "[tool.before]\nversion = \"99.0.0\"\n\n[project]\nversion = '1.2.3'\n"+ )+ commented_project = (+ '[project]\nname = "demo"\nversion = "2.3.4" # current release\n'+ )+ missing_project_version = (+ '[project]\nname = "demo"\n\n[[tool.items]]\nversion = "99.0.0"\n'+ )+ script = (+ f"const projectVersionPattern = {json.dumps(project_pattern)};\n"+ f"{function}\n"+ "process.stdout.write(JSON.stringify(["+ f"projectVersionFromToml({json.dumps(pyproject)}),"+ f"projectVersionFromToml({json.dumps(scoped_project)}),"+ f"projectVersionFromToml({json.dumps(commented_project)}),"+ f"projectVersionFromToml({json.dumps(missing_project_version)})"+ "]));"+ )++ assert _run_javascript(script) == [expected, "1.2.3", "2.3.4", None]+ assert "contents: read" in workflow+ assert "github.rest.repos.getContent" in workflow+ assert 'path: "pyproject.toml"' in workflow+ assert "context.payload.repository.default_branch" in workflow+ assert 'split(".").map((part) => BigInt(part))' in workflow+ assert "isOlderVersion(reportedVersion, latestVersion)" in workflow+++def test_outdated_version_comment_is_reconciled_across_edits() -> None:+ workflow = WORKFLOW.read_text(encoding="utf-8")+ latest = "17.23.456"+ source = f"return (async () => {{\n{_workflow_script()}\n}})();"+ harness = r"""+const run = new Function("github", "context", __SOURCE__);+const latestVersion = __LATEST__;+const comments = [];+const calls = [];+const liveIssue = { number: 7, labels: [], body: "" };+const record = (name, args) => calls.push({ name, args });+const github = {+ paginate: async () => comments,+ rest: {+ issues: {+ get: async (args) => {+ record("getIssue", args);+ return { data: liveIssue };+ },+ getLabel: async (args) => record("getLabel", args),+ createLabel: async (args) => record("createLabel", args),+ addLabels: async (args) => {+ record("addLabels", args);+ liveIssue.labels.push(...args.labels.map((name) => ({ name })));+ },+ removeLabel: async (args) => {+ record("removeLabel", args);+ liveIssue.labels = liveIssue.labels.filter((label) => label.name !== args.name);+ },+ createComment: async (args) => {+ record("createComment", args);+ comments.push({+ id: 100 + calls.filter((call) => call.name === "createComment").length,+ user: { login: "github-actions[bot]" },+ body: args.body,+ });+ },+ updateComment: async (args) => {+ record("updateComment", args);+ comments.find((comment) => comment.id === args.comment_id).body = args.body;+ },+ deleteComment: async (args) => {+ record("deleteComment", args);+ const index = comments.findIndex((comment) => comment.id === args.comment_id);+ if (index !== -1) comments.splice(index, 1);+ },+ },+ repos: {+ getContent: async (args) => {+ record("getContent", args);+ const content = `[tool.before]\nversion = "99.0.0"\n\n[project]\nversion = '${latestVersion}' # current release\n`;+ return {+ data: {+ type: "file",+ encoding: "base64",+ content: Buffer.from(content).toString("base64"),+ },+ };+ },+ },+ },+};+const context = {+ repo: { owner: "owner", repo: "repo" },+ payload: {+ issue: { number: 7, labels: [], body: "stale event snapshot" },+ repository: {+ default_branch: "main",+ html_url: "https://github.com/owner/repo",+ },+ },+};+const bodyFor = (value) => `### FCC version\n\n${value}\n\n### CLI\n\nClaude Code`;++liveIssue.body = bodyFor("latest");+await run(github, context);+liveIssue.body = bodyFor("The version is 17.23.454");+await run(github, context);+await run(github, context);+liveIssue.body = bodyFor("free-claude-code 17.23.455");+await run(github, context);+liveIssue.body = bodyFor(latestVersion);+await run(github, context);+comments.push({+ id: 102,+ user: { login: "github-actions[bot]" },+ body: "<!-- fcc-version-outdated -->\nstale",+});+liveIssue.labels = [{ name: "needs-fcc-version" }];+liveIssue.body = bodyFor("None");+await run(github, context);++process.stdout.write(JSON.stringify({ calls, comments }));+"""+ result = _run_javascript(+ harness.replace("__SOURCE__", json.dumps(source)).replace(+ "__LATEST__", json.dumps(latest)+ )+ )+ calls = result["calls"]+ names = [call["name"] for call in calls]+ content_reads = [call for call in calls if call["name"] == "getContent"]++ assert names.count("createComment") == 2+ assert names.count("updateComment") == 1+ assert names.count("deleteComment") == 3+ assert names.count("getContent") == 4+ assert names.count("getIssue") == 6+ assert names.count("getLabel") == 1+ assert names.count("addLabels") == 1+ assert names.count("removeLabel") == 2+ assert "createLabel" not in names+ assert all(call["args"]["path"] == "pyproject.toml" for call in content_reads)+ assert all(call["args"]["ref"] == "main" for call in content_reads)+ assert "`17.23.454`" in next(+ call["args"]["body"]+ for call in calls+ if call["name"] == "createComment"+ and "fcc-version-outdated" in call["args"]["body"]+ )+ assert "`17.23.455`" in next(+ call["args"]["body"] for call in calls if call["name"] == "updateComment"+ )+ assert f"`{latest}`" in next(+ call["args"]["body"] for call in calls if call["name"] == "updateComment"+ )+ assert result["comments"] == []+ assert "cancel-in-progress: false" in workflow+ assert "github.rest.issues.update({" not in workflow+ assert 'state: "closed"' not in workflowdiff --git a/tests/contracts/test_issue_forms.py b/tests/contracts/test_issue_forms.pynew file mode 100644index 00000000..bf5993cc--- /dev/null+++ b/tests/contracts/test_issue_forms.py@@ -0,0 +1,20 @@+from pathlib import Path++import pytest+++ ("filename", "label"),+ [+ ("bug-report.yml", "bug"),+ ("feature-request.yml", "enhancement"),+ ],+)+def test_issue_forms_classify_with_labels_not_title_prefixes(+ filename: str,+ label: str,+) -> None:+ form = Path(".github/ISSUE_TEMPLATE", filename).read_text(encoding="utf-8")++ assert f" - {label}" in form+ assert not any(line.startswith("title:") for line in form.splitlines())