The Lawfare Academy

Lawfare Group → Knowledge Institute → Lawfare Academy

← Back to program

← CS 220 — Web Applications, SQL and Software Engineering

Weeks 12–14

Version control, tests and delivery

Learning objectives

  • Explain and trace the mechanisms in version control, tests and delivery.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

Current study directions: the original Academy lessons, preparation chapters, worked explanations and complete optional models on LawfareGroup.com provide the required conceptual preparation. Retained publisher/reference chapters, source exercises and their historical assignment directions are optional further study. Outside visits and assessments are optional. Independent subject review and observed learner testing remain pending. This current notice supersedes earlier textbook-supported study directions preserved below and in historical companion pages.

Version control records changes and their relationships. A commit should represent a coherent change that can be reviewed and explained. A branch provides an independent line of work; merging integrates histories and may require resolving semantic conflicts even when text merges automatically. Secrets do not belong in commits. Deleting a secret from the current file does not remove it from history or revoke it.

A delivery pipeline should test the exact revision it deploys. Unit tests isolate rules; integration tests exercise real boundaries; end-to-end tests exercise visitor behavior. A screenshot cannot show that server authorization works. Use fixtures with duplicate names, empty lists, large values and denied access. A migration should have a compatibility and recovery plan; rolling back application files may not reverse a destructive database change.

Operational readiness includes observability and recovery. Log enough to diagnose failures while minimizing sensitive content. Monitor errors and latency as well as uptime. Rehearse restoration rather than merely asserting that backups exist. A failed deployment should leave a clear route to a known working revision. Define acceptance through concrete user tasks: create an order, retrieve it as its owner, reject another account, recover from a failed request and continue using existing records.

Worked reasoning These unit tests check a rule in isolation. They do not prove that the deployed endpoint actually calls this function or that roles come from a trusted source. An integration test must verify those connections. If the endpoint accepts role from submitted JSON, the rule can be correct while the system remains vulnerable.

Extended teaching and laboratory

Unit tests can establish a function’s behavior while the deployed route never calls it. Integration tests cross the actual boundary: authentication, routing, validation, persistence and serialization. A useful negative test attempts an operation as the wrong user and verifies both the response and the absence of data changes.

Deployment includes schema evolution. An application rollback can fail if a migration removed a column the previous version still requires. Expand-and-contract changes keep old and new application versions compatible during transition. Backups and restoration tests answer a different question from whether a migration script exits successfully.

Worked problem Version 2 renames customer_name to display_name by deleting the old column immediately. Version 1 remains on one running worker. Explain the failure and a safer sequence.

Step-by-step reasoning 1. The old worker can still query customer_name and fail after the migration. Rolling back application code alone does not restore the column.

  1. First add display_name without removing customer_name. Backfill and use a documented compatibility period with synchronized writes or a clear authoritative field.
  1. Deploy code that reads the new field with the required transition fallback. Verify old/new behavior and data reconciliation.
  1. Remove the old field only after all consumers have migrated and rollback requirements are resolved. Test recovery on a disposable copy first.

A repository records snapshots and relationships

Git separates the working tree, staging area and committed history. Editing a file changes the working tree. Adding selected changes stages a proposed snapshot; committing records that staged snapshot with metadata and parent relationships. A later unstaged edit is not included simply because the same file was staged earlier. Inspect both the unstaged diff and staged diff before committing. A useful commit is a coherent change whose purpose and verification can be explained, not a promise that every file in the directory was tested together.

In a fictional exercise, begin with a committed request handler. Edit validation and stage it, then edit its error text without staging again. The next commit contains the staged validation version, not the newer unstaged message. The working tree still contains that message afterward. `git status`, `git diff` and `git diff --staged` answer related but distinct questions. Reading these differences prevents a test run against one working tree from being described as a test of a different committed artifact.

Branches name lines of work, and a commit can have several descendants. Suppose main at M gains A, while a feature branch from M gains B. A merge combines histories and usually has both lines as parents when a merge commit is created. A clean textual merge does not prove semantic compatibility: A might rename a field while B introduces a query using the old name in a different file. Rebase instead replays changes onto another base and creates new commit identities. Rewriting history already shared with others requires coordination; use the project's established policy rather than force-pushing to make a graph look tidy.

Revert records a new commit reversing selected changes; it preserves the earlier history. Reset changes a reference and, depending on its mode, can also change staging/working state. These are not interchangeable recovery tools. For a published defect, a reviewed revert can be more understandable than erasing shared history. A reverted application still needs schema/data compatibility, so Git alone cannot reverse an irreversible migration or an external side effect.

Never commit passwords, tokens or private fixture data. Removing a credential from the latest file leaves earlier copies in history and may leave clones or build logs. Revoke/rotate a genuinely exposed credential through the appropriate authorized process; deleting text is not revocation. Ignore rules prevent some untracked files from being added inadvertently but do not make already tracked secrets disappear. This course's exercises use fictional identities and temporary data; no real credential is needed for the repository experiment.

Tests establish claims at named boundaries

A unit test isolates a rule, such as permission predicate or price calculation. An integration test checks the actual connection between components: the route must call validation with a trusted principal, write the intended transaction and serialize an authorized result. A browser test checks the visible interaction, including keyboard access, loading/error states and recovery. These layers overlap, but one does not automatically supply the observations of another. The preserved native test in which a correct helper is bypassed by a route is the concrete reason to keep route-level negative tests.

Write expected results from the specification before invoking the implementation. For an order with two independent 500-cent lines, the expected total is 1000. Do not compute the expected total with the same report query whose join grain is under investigation. Include emptiness, duplicate values, malformed data, denied access, stale state and failures after partial work has begun. A test that asserts only “an exception occurred” can miss a partially committed row; inspect the post-failure state as well.

Use isolated fixtures. A database test should create known fictional rows in a disposable database or a deliberately isolated test schema, not query learner or production records. Control time, random seeds and external responses where needed for reproducibility, and label a simulated boundary as simulated. Mocking a database exception demonstrates the coordinator's selected reaction, while a real constraint failure demonstrates more of the database transaction boundary. Neither establishes a deployed database engine's complete concurrency or crash behavior.

For asynchronous UI behavior, give tests explicit response control instead of hoping a timing delay reproduces a race. Start A, start B, complete B successfully, then reject A. The displayed state must still belong to B. Repeat with B empty, malformed, denied and disconnected. A fixed sleep that happens to pass once is weak evidence that the correct completion event was observed. Wait for the state that expresses the contract and record what was actually tested.

Cross-browser work should target meaningful platform differences and supported configurations. A layout can render well in one browser while keyboard focus, native validation, date inputs or an API behave differently elsewhere. Use semantic markup, feature detection where appropriate and a declared support policy. Automated accessibility checks can find certain structural defects; they do not replace inspection of focus order, understandable error recovery or observed use with assistive technology. Do not claim a real mobile-device test from a desktop viewport emulation.

A delivery pipeline must identify the artifact

Continuous integration runs a declared set of checks on an identified revision in a controlled environment. A pipeline might install pinned dependencies, perform syntax/type/build checks, run unit/integration fixtures and package an artifact. A green result is bounded by its actual job definitions and environment. If the build tested revision A but deployment takes a fresh unverified working tree B, the badge does not establish B's behavior. Record the commit, runtime/dependency versions, commands and artifact digest where useful.

Separate build-time configuration from runtime configuration and secrets. A static frontend cannot safely hold a server credential merely because the source uses an environment-variable name: build tools can embed values into delivered JavaScript. Inspect which variables become public artifacts. Dependency versions and a lockfile improve repeatability, while security updates still require evaluation; pinning a vulnerable package forever is not a sound maintenance policy. Run checks with the same relevant framework/database versions as the deployment or state the difference.

A deployment changes a serving system, not just a source folder. Specify where requests terminate, how application workers start, how static assets are served, where persistent state lives and how configuration reaches each process. A local development server is convenient for debugging but is not an automatic production serving configuration. Disable development-only behavior, use the framework's production checks and arrange transport/proxy configuration deliberately. Verify a real public route and its denied/failure paths after release; upload acknowledgement or a process-start message is not persistence or visitor-behavior evidence.

Use staged rollout where the environment supports it. A canary exposes a selected portion of traffic to the candidate under a stated policy; a blue/green approach switches between serving environments. Both require compatible state and a clear rollback decision. They do not make a destructive schema change reversible or remove the need to know which revision served a particular failed request. Avoid inventing traffic or a successful canary observation when the exercise only describes a plan.

Schema changes, backups and restoration

The original expand-and-contract case establishes mixed-version compatibility. Extend it into a release contract: first add a compatible representation, backfill under a justified rule, deploy readers/writers that preserve the transition invariant, reconcile data and remove the old representation only after all consumers and rollback needs are resolved. A migration can pass on an empty database and fail against historical rows. Test representative old records and mixed writer behavior, including interruption during backfill.

A backup has a scope, a point in time and a restoration procedure. A logical SQL dump represents selected database objects/data under its tool and transaction options; it is not automatically a byte-for-byte disk image, a complete collection of external files or a guarantee of every cluster role/setting. Restore into an isolated target, verify schema and constraints, reconcile counts and selected independent totals, then exercise the application against it. The fact that the backup file exists or that the dump command exited zero does not establish recoverability.

Recovery objectives express different limits. An acceptable data-loss interval concerns the recovery point; an acceptable outage duration concerns recovery time. If backups are hourly and a failure occurs 50 minutes after the last usable snapshot, restoring only that snapshot may lose those 50 minutes of later accepted changes. Additional logs/replication may change that result under an actual tested policy. A backup is not a substitute for a rollback compatible with the current data, and replication can reproduce an erroneous deletion rather than preserving the earlier intended state.

Observability connects symptoms to causes without disclosing unnecessary sensitive data. Record a request/run ID, serving revision, operation category, result and timing where appropriate; avoid logging passwords, bearer tokens and entire private bodies. A rising error rate, slow tail latency and a dependency failure answer different operational questions. A liveness endpoint can show that a process responds; a readiness check asks whether it can serve its essential workflow. Bounded synthetic transactions on fictional data can supply stronger evidence but need isolation and cleanup policies.

Optional release record and complete model

Commit C passes a helper-only authorization test. The package actually contains an unstaged route edit accepting `role=admin` from the request. A migration then removes customer_name while one C worker still reads it. The team has an hourly dump but has never restored one. Explain four independent defects in the release claim and specify the smallest useful evidence for each. Change the scenario so the package really is C but a request fails only after the audit insert begins.

**Model reasoning.** First, the tested revision and packaged working tree differ. Record and test the exact artifact, inspecting staged/unstaged changes rather than claiming C covers another tree. Second, a helper test does not exercise the hostile role through the route; call that route as an ordinary fictional customer, request another customer's object and verify denial plus no mutation/private response. Third, the migration invalidates an old worker and code-only rollback; use compatible expand/backfill/read-write/contract stages and test mixed versions. Fourth, an untested dump is not a demonstrated restoration path; restore into a disposable target and reconcile database plus application behavior. In the changed case, inject the actual documented audit failure inside the local transaction and query both domain and audit state afterward. A clean error response alone does not show rollback. None of these tests authorizes a real external payment or establishes every production crash mode.

Evaluate on four equal criteria: accurate Git snapshot/history reasoning; independent expectations and real boundary tests; exact artifact/configuration/deployment correspondence; and compatible data recovery with explicit limits. Preserve the original migration and route-bypass investigations. No remote repository history, production deployment, real credential or learner record was changed to write it.

Apply the idea

Version 2 renames customer_name to display_name by deleting the old column immediately. Version 1 remains on one running worker. Explain the failure and a safer sequence.

A unit authorization test passes, but the endpoint accepts role=admin from submitted JSON. Design the integration test that exposes it.

Read the worked reasoning

Authenticate as an ordinary customer, submit role=admin with a request targeting another customer’s order, and verify denial plus no database change. Then verify the permitted operation on the customer’s own order. The test must call the real route so a correct helper cannot conceal an untrusted role source.

Check understanding

Why are unit authorization tests insufficient alone?

  1. The endpoint might bypass the tested rule or supply untrusted identity data
    Feedback

    The complete boundary must also be exercised.

  2. Unit tests automatically exercise production routing
    Feedback

    Isolated function tests do not invoke every route.

  3. Passing tests remove the need for integration
    Feedback

    Each test level supplies different evidence.

Further reading

Current study directions: the original Academy lessons, preparation chapters, worked explanations and complete optional models on LawfareGroup.com provide the required conceptual preparation. Retained publisher/reference chapters, source exercises and their historical assignment directions are optional further study. Outside visits and assessments are optional. Independent subject review and observed learner testing remain pending. This current notice supersedes earlier textbook-supported study directions preserved below and in historical companion pages.

Use the complete original preparation chapter, preserved investigation and optional changed-record reasoning for this unit. Earlier source directions remain in immutable edition 4.

My learning →