From 35605c33b903742cd13d444a1a14d61b07fbaa86 Mon Sep 17 00:00:00 2001 From: Sergio Espinal Date: Wed, 21 Oct 2026 23:07:42 +0000 Subject: [PATCH 1/2] Add pricing checks and controlled defect for issue #8 --- .gitignore | 2 ++ Jenkinsfile | 28 ++++++++++++---------------- pricing.py | 4 ++++ tests/test_pricing.py | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 .gitignore create mode 100644 pricing.py create mode 100644 tests/test_pricing.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43ae0e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +*.py[cod] diff --git a/Jenkinsfile b/Jenkinsfile index 722ba9b..b9b37f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,30 +1,26 @@ pipeline { - agent any - + agent { label 'controller-small-trusted' } + options { + skipDefaultCheckout() + disableConcurrentBuilds() + timeout(time: 5, unit: 'MINUTES') + buildDiscarder(logRotator(numToKeepStr: '20')) + } stages { stage('Checkout') { steps { checkout scm + sh 'git rev-parse HEAD && python3 --version' } } - - stage('Lint') { + stage('Syntax check') { steps { - sh ''' - set -eu - test -f README.md - grep -qi "startup" README.md - ''' + sh 'python3 -m py_compile pricing.py tests/test_pricing.py' } } - - stage('Automated Test') { + stage('Unit tests') { steps { - sh ''' - set -eu - printf "CI smoke test for startup-product\\n" - find . -maxdepth 2 -type f | sort | head -20 - ''' + sh 'python3 -m unittest discover -s tests -v' } } } diff --git a/pricing.py b/pricing.py new file mode 100644 index 0000000..0a99fb1 --- /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..34a2be6 --- /dev/null +++ b/tests/test_pricing.py @@ -0,0 +1,17 @@ +import unittest + +from pricing import total_price + + +class PricingTests(unittest.TestCase): + def test_total(self): + self.assertEqual(total_price(10, 3), 30) + + def test_single_item(self): + self.assertEqual(total_price(12.5, 1), 12.5) + + def test_invalid_quantity(self): + for quantity in (0, -1): + with self.subTest(quantity=quantity): + with self.assertRaises(ValueError): + total_price(10, quantity) From ed8684a2897c407946320183e572f6412dbb7703 Mon Sep 17 00:00:00 2001 From: Sergio Espinal Date: Wed, 21 Oct 2026 23:11:38 +0000 Subject: [PATCH 2/2] Fix pricing multiplication and document clean CI run for issue #8 --- README.md | 20 +++++++++++++++++++- pricing.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29e0204..9bfc994 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository supports the Chapter 2 Gitea foundation assignment. It is used t - Gitea is running from a pinned official container image. - SQLite data and repositories are stored in persistent host-mounted storage. -- The current HTTP URL is temporary until DNS and HTTPS are configured. +- Gitea uses https://git.sespinal590.dev/ through the Caddy TLS proxy. ## Product Vision @@ -19,3 +19,21 @@ Target users are SSW 590 team members who need a shared place to plan, review, a 1. Issue tracking workflow: maintain product and operations issues with clear acceptance criteria. 2. Pull request review workflow: require changes to be proposed on branches and reviewed before merge. 3. Operations evidence workflow: record restart, persistence, DNS, HTTPS, and firewall verification evidence in the IT manual. + + +## Chapter 4 tested application + +This repository uses the assignment manual's permitted minimal Python pricing application. `total_price` multiplies a unit price by a positive quantity and rejects zero/negative quantities. It is a course CI example, not a claim of a production pricing system. + +Requirements: Python 3 (the Jenkins executor records its exact version), Git, and the Python standard library. No pip packages, Docker daemon, or Docker socket are needed for these checks. + +From a clean clone, reproduce the Jenkins checks with: + +```sh +python3 -m py_compile pricing.py tests/test_pricing.py +python3 -m unittest discover -s tests -v +``` + +Expected: syntax check exits 0; three unit tests pass. The controlled demonstration changes multiplication to addition, causing the total and single-item tests to fail. The repair restores multiplication on the same PR. + +Jenkins polls Gitea for PR updates. Its multibranch source tests PR heads (not synthetic merge commits) and publishes `startup-product-ci/pipeline/pr-main` for this PR to main. Branch protection requires that check and one real peer approval, dismisses stale approvals, and disallows direct pushes and admin merge bypass. Only trusted team members may change pipeline code. Builds execute on the controller in this resource-constrained course deployment; untrusted fork PR discovery is disabled. 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