Agent Wranglers

TST-45Recommended

Compare the live system before and after each deploy

Before and after each deploy, fetch every public address with fixed request headers. Record status, key headers and a body hash. The live diff must match the local diff.

How to do it

Build the address list from the sitemap and add the machine files. These include robots.txt, feeds, sitemaps, /.well-known/ files, API endpoints and known redirects. Send the same Accept, Accept-Encoding and User-Agent on every request, and never follow redirects. Record content-type, cache-control, location and the security headers. Apply the masks before hashing bodies. This runs next to the smoke test and the rollback.

Examples

JavaScript example

const HEADERS = ['content-type', 'cache-control', 'location', 'content-security-policy', 'strict-transport-security']
const REQUEST = { redirect: 'manual', headers: { 'accept': '*/*', 'accept-encoding': 'identity', 'user-agent': 'output-compare/1' } }

async function snapshot(urls) {
  const entries = []
  for (const url of urls) {
    const response = await fetch(url, REQUEST)
    const body = new Uint8Array(await response.arrayBuffer())
    const digest = Buffer.from(await crypto.subtle.digest('SHA-256', body)).toString('hex')
    entries.push({ url, status: response.status, headers: Object.fromEntries(HEADERS.map(name => [name, response.headers.get(name)])), sha256: digest })
  }
  return entries
}

const urls = ['https://example.com/robots.txt', 'https://example.com/feed.xml', 'https://example.com/old-pricing']
console.log(JSON.stringify(await snapshot(urls), null, 2))

Python example

import hashlib, json, urllib.error, urllib.request

HEADERS = ["content-type", "cache-control", "location", "content-security-policy", "strict-transport-security"]
REQUEST_HEADERS = {"Accept": "*/*", "Accept-Encoding": "identity", "User-Agent": "output-compare/1"}

class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, *args):
        return None

opener = urllib.request.build_opener(NoRedirect)

def fetch(url):
    try:
        response = opener.open(urllib.request.Request(url, headers=REQUEST_HEADERS))
    except urllib.error.HTTPError as error:
        response = error
    body = response.read()
    return {"url": url, "status": response.status,
            "headers": {name: response.headers.get(name) for name in HEADERS},
            "sha256": hashlib.sha256(body).hexdigest()}

urls = ["https://example.com/robots.txt", "https://example.com/feed.xml", "https://example.com/old-pricing"]
print(json.dumps([fetch(u) for u in urls], indent=2))

How to check

After each deploy, a job compares the two snapshots against the expected paths. One address that changed and is not listed raises an alert or rolls the deploy back.

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/testing/output-comparison/compare-live-before-and-after">Agent Wranglers testing playbook</a>. In code you write, add a comment next to it with the same link.