From 041adfcda4d37d7c1da7de1861d98cc98e6e64b2 Mon Sep 17 00:00:00 2001 From: "Codex (authorized Assignment 5 implementation)" Date: Fri, 9 Oct 2026 18:33:17 +0000 Subject: [PATCH 1/5] Add Assignment 6 Python application and Jenkins pipeline --- Jenkinsfile | 29 +++++++++++++++++++++++++++++ ops/jenkins/README.md | 24 ++++++++++++++++++++++++ ops/jenkins/compose.jenkins.yaml | 17 +++++++++++++++++ ops/jenkins/install-python.sh | 6 ++++++ pricing.py | 4 ++++ tests/test_pricing.py | 11 +++++++++++ 6 files changed, 91 insertions(+) create mode 100644 Jenkinsfile create mode 100644 ops/jenkins/README.md create mode 100644 ops/jenkins/compose.jenkins.yaml create mode 100644 ops/jenkins/install-python.sh create mode 100644 pricing.py create mode 100644 tests/test_pricing.py diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..55c1a94 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,29 @@ +pipeline { + agent any + options { + skipDefaultCheckout() + disableConcurrentBuilds() + timeout(time: 5, unit: 'MINUTES') + buildDiscarder(logRotator(numToKeepStr: '10')) + timestamps() + } + stages { + stage('Checkout') { + steps { + checkout scm + sh 'git rev-parse HEAD' + } + } + stage('Syntax check') { + steps { + sh 'python3 --version' + sh 'python3 -m py_compile pricing.py tests/test_pricing.py' + } + } + stage('Test') { + steps { + sh 'python3 -m unittest discover -s tests -v' + } + } + } +} diff --git a/ops/jenkins/README.md b/ops/jenkins/README.md new file mode 100644 index 0000000..33b385c --- /dev/null +++ b/ops/jenkins/README.md @@ -0,0 +1,24 @@ +# Assignment 6 Python CI + +The pipeline runs on the trusted Jenkins controller executor. Only trusted +team members may change pipeline code. Do not supply secrets or privileged +Docker access to untrusted pull requests. Fork PR discovery is disabled. + +The controller uses the official Jenkins LTS image recorded in compose.jenkins.yaml. +Python comes from that image's Debian package repositories; record the actual +Python version from each build. No pip dependencies or Docker socket are needed. +After replacing the container, run `sh ops/jenkins/install-python.sh` on the +Droplet before building. A restart retains Python; replacement requires reinstall. +Jenkins jobs and settings persist in the jenkins-home volume. + +From the repository root, reproduce checks with: + + python3 -m py_compile pricing.py tests/test_pricing.py + python3 -m unittest discover -s tests -v + +Expected: both tests pass. Syntax or test failures must fail the Jenkins run. +Multibranch origin PR discovery tests the current PR revision, not a merged revision. +The printed checkout commit identifies what was actually tested. + +Webhook delivery, status reporting, branch protection, and the controlled +failure/repair demonstration must be configured and verified separately. diff --git a/ops/jenkins/compose.jenkins.yaml b/ops/jenkins/compose.jenkins.yaml new file mode 100644 index 0000000..f0b937e --- /dev/null +++ b/ops/jenkins/compose.jenkins.yaml @@ -0,0 +1,17 @@ +services: + jenkins: + image: jenkins/jenkins@sha256:a660310e39ade10631f774bacd5219de767dfd08947ea5c32a739b5e5bb382c1 + container_name: myfileagent-jenkins + restart: unless-stopped + environment: + JAVA_OPTS: "-Xms64m -Xmx256m" + mem_limit: 448m + ports: + - "127.0.0.1:8080:8080" + volumes: + - jenkins-home:/var/jenkins_home + networks: + - gitea-private + +volumes: + jenkins-home: diff --git a/ops/jenkins/install-python.sh b/ops/jenkins/install-python.sh new file mode 100644 index 0000000..b257d56 --- /dev/null +++ b/ops/jenkins/install-python.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# Run on the Droplet after recreating the official Jenkins container. +# Python installed in the container survives restart, not container replacement. +set -eu +docker exec -u root myfileagent-jenkins sh -c 'apt-get update -qq && apt-get install -y --no-install-recommends python3' +docker exec myfileagent-jenkins python3 --version diff --git a/pricing.py b/pricing.py new file mode 100644 index 0000000..446eda4 --- /dev/null +++ b/pricing.py @@ -0,0 +1,4 @@ +def total_price(unit_price, quantity): + if quantity < 1: + raise ValueError("Quantity must be positive") + return unit_price * quantity diff --git a/tests/test_pricing.py b/tests/test_pricing.py new file mode 100644 index 0000000..573f010 --- /dev/null +++ b/tests/test_pricing.py @@ -0,0 +1,11 @@ +import unittest +from pricing import total_price + + +class PricingTests(unittest.TestCase): + def test_total(self): + self.assertEqual(total_price(10, 3), 30) + + def test_invalid_quantity(self): + with self.assertRaises(ValueError): + total_price(10, 0) -- 2.54.0 From ad056a363cde9d8b2fe988da95047a07996c1a66 Mon Sep 17 00:00:00 2001 From: nkogut Date: Fri, 9 Oct 2026 19:02:06 +0000 Subject: [PATCH 2/5] Update project name to MyFileAgent --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index df59bb1..fb04610 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ ## Product Scope -FilePilot demonstrates a controlled file-update workflow. It accepts a target +MyFileAgent demonstrates a controlled file-update workflow. It accepts a target file description, expected text, and replacement text. The application locates the file only within an approved demonstration directory, verifies the expected text, creates a backup, presents a diff, performs the replacement, verifies the result, and records the outcome. -FilePilot does not provide unrestricted filesystem access, general desktop +MyFileAgent does not provide unrestricted filesystem access, general desktop control, arbitrary shell execution, or open-ended autonomous planning. ## Demonstration Acceptance Criteria -The demonstration succeeds when FilePilot: +The demonstration succeeds when MyFileAgent: 1. finds the approved project-status file; 2. confirms that it contains `Status: Draft`; -- 2.54.0 From d6477b3df620383ca6215d2455f9e40d457e3513 Mon Sep 17 00:00:00 2001 From: "Codex (authorized Assignment 5 implementation)" Date: Fri, 9 Oct 2026 19:04:32 +0000 Subject: [PATCH 3/5] Demonstrate failing pricing calculation for issue #10 --- pricing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pricing.py b/pricing.py index 446eda4..0a99fb1 100644 --- a/pricing.py +++ b/pricing.py @@ -1,4 +1,4 @@ def total_price(unit_price, quantity): if quantity < 1: raise ValueError("Quantity must be positive") - return unit_price * quantity + return unit_price + quantity -- 2.54.0 From 02d31699aaf13b3e4d18865d34c16a2bb46135c6 Mon Sep 17 00:00:00 2001 From: "Codex (authorized Assignment 5 implementation)" Date: Fri, 9 Oct 2026 19:05:51 +0000 Subject: [PATCH 4/5] Repair pricing multiplication and restore passing CI for #10 --- pricing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pricing.py b/pricing.py index 0a99fb1..446eda4 100644 --- a/pricing.py +++ b/pricing.py @@ -1,4 +1,4 @@ def total_price(unit_price, quantity): if quantity < 1: raise ValueError("Quantity must be positive") - return unit_price + quantity + return unit_price * quantity -- 2.54.0 From b7ef4850b74bbb7169871684a385a7bfad7beee8 Mon Sep 17 00:00:00 2001 From: "Codex (authorized Assignment 5 implementation)" Date: Fri, 9 Oct 2026 19:08:59 +0000 Subject: [PATCH 5/5] Record private webhook configuration and enforced PR merge gate --- ops/jenkins/Caddyfile.jenkins | 7 +++++ ops/jenkins/README.md | 35 ++++++++++++++++++++++ ops/jenkins/compose.webhook.yaml | 7 +++++ ops/jenkins/main-branch-protection.json | 40 +++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 ops/jenkins/Caddyfile.jenkins create mode 100644 ops/jenkins/compose.webhook.yaml create mode 100644 ops/jenkins/main-branch-protection.json diff --git a/ops/jenkins/Caddyfile.jenkins b/ops/jenkins/Caddyfile.jenkins new file mode 100644 index 0000000..ce61890 --- /dev/null +++ b/ops/jenkins/Caddyfile.jenkins @@ -0,0 +1,7 @@ +# Merge this site block into the deployment's existing Caddyfile. +# Gitea delivers directly to Jenkins through the private Docker bridge. +ci.myfileagent.tech { + @giteaHook path /gitea-webhook /gitea-webhook/* + respond @giteaHook "Webhook is available only on the private network" 403 + reverse_proxy jenkins:8080 +} diff --git a/ops/jenkins/README.md b/ops/jenkins/README.md index 33b385c..5e4269f 100644 --- a/ops/jenkins/README.md +++ b/ops/jenkins/README.md @@ -22,3 +22,38 @@ The printed checkout commit identifies what was actually tested. Webhook delivery, status reporting, branch protection, and the controlled failure/repair demonstration must be configured and verified separately. + +## Gitea webhook and required merge gate + +Configure the repository Gitea webhook with POST, application/json, active, +push and pull-request events, branch filter `*`, and target +`http://jenkins:8080/gitea-webhook/post`. Gitea must allow the exact `jenkins` +host through its webhook destination allowlist; see `compose.webhook.yaml`. +The deployed base Compose file includes this same environment setting. +The hook is configured manually, so Jenkins does not manage repository hooks. + +The installed Gitea plugin handler does not verify a shared-secret signature. +Leave the hook secret empty and use the existing private Docker network. +Block `/gitea-webhook` and `/gitea-webhook/*` at the public Caddy site, as in +`Caddyfile.jenkins`. Raw port 8080 remains loopback-only. Do not claim HMAC +authentication, and do not expose the unsigned receiver publicly. + +Require `myfileagent-python-ci/pipeline/pr-main` on `main`; this is the +observed PR-head context. The branch context ending `/pipeline/head` is +not the PR context. `main-branch-protection.json` records the applied rule: +no direct or force pushes, one approval, dismiss stale approvals, reject +changes-requested reviews, and no administrator merge override. + +October 9, 2026 acceptance exercise, linked to issue #10 and PR #11: +- PR build 1 passed on ad056a3 after a real pull-request-open webhook. +- Commit d6477b3 changed multiplication to addition; PR build 2 failed with + `AssertionError: 13 != 30`; Gitea showed the required check failed. +- Commit 02d3169 restored multiplication; the webhook started PR build 3, + which passed both tests and updated the same required context. +- PR #11 remains open for reviewer nkogut. No review approval or merge has + been performed by automation. + +For delivery diagnosis, inspect Gitea's recent delivery response and compare +its event/head SHA with Jenkins' console. A 200 `Processed` delivery alone +is not proof that tests passed. Save the failed and repaired PR gate views +before further commits. A new commit needs a new success status and review. diff --git a/ops/jenkins/compose.webhook.yaml b/ops/jenkins/compose.webhook.yaml new file mode 100644 index 0000000..2ccaecb --- /dev/null +++ b/ops/jenkins/compose.webhook.yaml @@ -0,0 +1,7 @@ +# Apply with the existing base compose.yaml and compose.jenkins.yaml. +# Allows only the named Jenkins destination in addition to Gitea's default +# external destinations; never use '*' to allow every private address. +services: + gitea: + environment: + GITEA__webhook__ALLOWED_HOST_LIST: "external,jenkins" diff --git a/ops/jenkins/main-branch-protection.json b/ops/jenkins/main-branch-protection.json new file mode 100644 index 0000000..11cd50c --- /dev/null +++ b/ops/jenkins/main-branch-protection.json @@ -0,0 +1,40 @@ +{ + "branch_name": "main", + "rule_name": "main", + "priority": 1, + "enable_push": false, + "enable_push_whitelist": false, + "push_whitelist_usernames": [], + "push_whitelist_teams": [], + "push_whitelist_deploy_keys": false, + "enable_force_push": false, + "enable_force_push_allowlist": false, + "force_push_allowlist_usernames": [], + "force_push_allowlist_teams": [], + "force_push_allowlist_deploy_keys": false, + "enable_merge_whitelist": false, + "merge_whitelist_usernames": [], + "merge_whitelist_teams": [], + "enable_bypass_allowlist": false, + "bypass_allowlist_usernames": [], + "bypass_allowlist_teams": [], + "enable_status_check": true, + "status_check_contexts": [ + "myfileagent-python-ci/pipeline/pr-main" + ], + "required_approvals": 1, + "enable_approvals_whitelist": false, + "approvals_whitelist_username": [], + "approvals_whitelist_teams": [], + "block_on_rejected_reviews": true, + "block_on_official_review_requests": true, + "block_on_outdated_branch": false, + "dismiss_stale_approvals": true, + "ignore_stale_approvals": false, + "require_signed_commits": false, + "protected_file_patterns": "", + "unprotected_file_patterns": "", + "block_admin_merge_override": true, + "created_at": "2026-10-09T19:03:48Z", + "updated_at": "2026-10-09T19:04:32Z" +} \ No newline at end of file -- 2.54.0