{
  "schema": 1,
  "sqlstate": "08001",
  "condition_name": "sqlclient_unable_to_establish_sqlconnection",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "dblink_connect_failure",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A runner-owned disposable target is provisioned."
      ],
      "trigger": "Connect to a runner-local refused port through server-side dblink.",
      "assertions": [
        "The selected server diagnostic has the expected SQLSTATE",
        "The selected recovery/probe assertions pass",
        "Runner-owned resources are cleaned up"
      ],
      "repair": "Follow the case-specific repair statements and verify the resulting state.",
      "cleanup": "Drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "dblink_connect_failure",
      "case_id": "dblink_connect_failure",
      "language": "sql",
      "statements": {
        "create_extension": "CREATE EXTENSION IF NOT EXISTS dblink",
        "trigger": "SELECT dblink_connect('missing_remote', 'host=127.0.0.1 port=1 dbname=postgres connect_timeout=1')",
        "open": "SELECT dblink_connect('working_remote', 'host=runner_host port=runner_port dbname=runner_db user=runner_user connect_timeout=5')",
        "remote_probe": "SELECT * FROM dblink('working_remote', 'SELECT 1') AS result(value integer)",
        "disconnect": "SELECT dblink_disconnect('working_remote')",
        "probe": "SELECT 1"
      }
    }
  ],
  "runtime": [
    {
      "id": "runtime.08001-dblink-repair-latest2.latest",
      "kind": "runtime_observation",
      "run_id": "08001-dblink-repair-latest2",
      "target": "latest",
      "status": "passed",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "cases": [
        "dblink_connect_failure"
      ],
      "summary_sha256": "5dace2836aa9b1c47208ad250c2f527fb65c6947db4c7167cb210721eb92b4c6",
      "raw_sha256": "076f97e40f38907d27d3436ac7657fefbb521ef313898410efabc7032908092a",
      "case_manifest_sha256": "d1310befd467814a86638f37b0b2fc4ede637b6a459e511d5e9eacccf0e1cadd",
      "snippet_registry": {
        "sha256": "8227f1b7b90faa2fd296bc921279c0f357637ae39695f481f9979af01b22e93e"
      },
      "environment": {
        "target_kind": "latest",
        "server_version": "18.6 (Homebrew)",
        "server_version_num": "180006",
        "machine": "arm64",
        "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
        "libpq_version": "18.6",
        "psycopg_version": "3.3.5",
        "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
        "locale": "en_US.UTF-8",
        "lc_messages": "C",
        "log_destination": "csvlog,jsonlog"
      },
      "observed": {
        "connection_autocommit": true,
        "connection_scope": "server-side dblink connection to the same runner-owned target and a refused runner-local port",
        "dblink_repair": {
          "disconnected": "OK",
          "opened": "OK",
          "remote_probe": 1
        },
        "diagnostic": {
          "column_name": null,
          "constraint_name": null,
          "context": null,
          "datatype_name": null,
          "exception_type": "SqlclientUnableToEstablishSqlconnection",
          "internal_position": null,
          "internal_query": null,
          "message_detail": "connection to server at \"127.0.0.1\", port 1 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?",
          "message_hint": null,
          "message_primary": "could not establish connection",
          "schema_name": null,
          "severity": "ERROR",
          "severity_nonlocalized": "ERROR",
          "source_file": "dblink.c",
          "source_function": "dblink_connect",
          "source_line": "338",
          "sqlstate": "08001",
          "statement_position": null,
          "table_name": null,
          "text": "could not establish connection\nDETAIL:  connection to server at \"127.0.0.1\", port 1 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?"
        },
        "probe": 1,
        "statuses": {
          "after_error": "IDLE",
          "final": "IDLE"
        }
      },
      "assertions": [
        {
          "expected": "08001",
          "name": "dblink connection SQLSTATE",
          "observed": "08001",
          "passed": true
        },
        {
          "expected": "could not establish connection",
          "name": "dblink connection diagnostic",
          "observed": "could not establish connection",
          "passed": true
        },
        {
          "expected": "IDLE",
          "name": "failed connection attempt leaves session usable",
          "observed": "IDLE",
          "passed": true
        },
        {
          "expected": "OK and remote SELECT 1",
          "name": "correct dblink connection can be repaired",
          "observed": {
            "open": "OK",
            "remote": 1
          },
          "passed": true
        },
        {
          "expected": "OK",
          "name": "named dblink handle is explicitly released",
          "observed": "OK",
          "passed": true
        },
        {
          "expected": "SELECT 1 and IDLE",
          "name": "owner session remains usable",
          "observed": {
            "probe": 1,
            "status": "IDLE"
          },
          "passed": true
        }
      ],
      "cleanup": {
        "case": {
          "errors": [],
          "passed": true
        }
      },
      "limits": "Disposable runner-owned target only; this is a bounded mechanism case, not a guarantee for every client or network path.",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 88186,
          "binary": {
            "bindir": "/opt/homebrew/Cellar/postgresql@18/18.6/bin",
            "pg_config": "/opt/homebrew/bin/pg_config",
            "pg_config_version": "PostgreSQL 18.6 (Homebrew)",
            "postgres": "/opt/homebrew/Cellar/postgresql@18/18.6/bin/postgres"
          },
          "connection_scope": "runner-owned localhost port",
          "current_user": "runner",
          "docker": {},
          "lc_messages": "C",
          "libpq_version": "18.6",
          "locale": "en_US.UTF-8",
          "log_destination": "csvlog,jsonlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "18.6 (Homebrew)",
          "server_version_num": "180006",
          "target_kind": "latest",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "08001",
                "name": "dblink connection SQLSTATE",
                "observed": "08001",
                "passed": true
              },
              {
                "expected": "could not establish connection",
                "name": "dblink connection diagnostic",
                "observed": "could not establish connection",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "failed connection attempt leaves session usable",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "OK and remote SELECT 1",
                "name": "correct dblink connection can be repaired",
                "observed": {
                  "open": "OK",
                  "remote": 1
                },
                "passed": true
              },
              {
                "expected": "OK",
                "name": "named dblink handle is explicitly released",
                "observed": "OK",
                "passed": true
              },
              {
                "expected": "SELECT 1 and IDLE",
                "name": "owner session remains usable",
                "observed": {
                  "probe": 1,
                  "status": "IDLE"
                },
                "passed": true
              }
            ],
            "case_id": "dblink_connect_failure",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.021,
            "observed": {
              "connection_autocommit": true,
              "connection_scope": "server-side dblink connection to the same runner-owned target and a refused runner-local port",
              "dblink_repair": {
                "disconnected": "OK",
                "opened": "OK",
                "remote_probe": 1
              },
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "SqlclientUnableToEstablishSqlconnection",
                "internal_position": null,
                "internal_query": null,
                "message_detail": "connection to server at \"127.0.0.1\", port 1 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?",
                "message_hint": null,
                "message_primary": "could not establish connection",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "dblink.c",
                "source_function": "dblink_connect",
                "source_line": "338",
                "sqlstate": "08001",
                "statement_position": null,
                "table_name": null,
                "text": "could not establish connection\nDETAIL:  connection to server at \"127.0.0.1\", port 1 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?"
              },
              "probe": 1,
              "statuses": {
                "after_error": "IDLE",
                "final": "IDLE"
              }
            },
            "schema": "c08001_dblink_connect_failure",
            "status": "passed"
          }
        ]
      }
    },
    {
      "id": "runtime.08001-dblink-repair-pg10c.pg10",
      "kind": "runtime_observation",
      "run_id": "08001-dblink-repair-pg10c",
      "target": "pg10",
      "status": "passed",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "cases": [
        "dblink_connect_failure"
      ],
      "summary_sha256": "339c3ec9564d613ce80e4801dffb5de90b505bd1af2a0f33d84b7ef870643035",
      "raw_sha256": "7257f77a09d23b2ae709bd550f2815f3d18b51d7e03bf3760c99211bb945db93",
      "case_manifest_sha256": "d1310befd467814a86638f37b0b2fc4ede637b6a459e511d5e9eacccf0e1cadd",
      "snippet_registry": {
        "sha256": "8227f1b7b90faa2fd296bc921279c0f357637ae39695f481f9979af01b22e93e"
      },
      "environment": {
        "target_kind": "pg10",
        "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
        "server_version_num": "100021",
        "machine": "arm64",
        "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
        "libpq_version": "18.6",
        "psycopg_version": "3.3.5",
        "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
        "locale": "en_US.UTF-8",
        "lc_messages": "en_US.utf8",
        "log_destination": "csvlog"
      },
      "observed": {
        "connection_autocommit": true,
        "connection_scope": "server-side dblink connection to the same runner-owned target and a refused runner-local port",
        "dblink_repair": {
          "disconnected": "OK",
          "opened": "OK",
          "remote_probe": 1
        },
        "diagnostic": {
          "column_name": null,
          "constraint_name": null,
          "context": null,
          "datatype_name": null,
          "exception_type": "SqlclientUnableToEstablishSqlconnection",
          "internal_position": null,
          "internal_query": null,
          "message_detail": "could not connect to server: Connection refused\n\tIs the server running on host \"127.0.0.1\" and accepting\n\tTCP/IP connections on port 1?",
          "message_hint": null,
          "message_primary": "could not establish connection",
          "schema_name": null,
          "severity": "ERROR",
          "severity_nonlocalized": "ERROR",
          "source_file": "dblink.c",
          "source_function": "dblink_connect",
          "source_line": "302",
          "sqlstate": "08001",
          "statement_position": null,
          "table_name": null,
          "text": "could not establish connection\nDETAIL:  could not connect to server: Connection refused\n\tIs the server running on host \"127.0.0.1\" and accepting\n\tTCP/IP connections on port 1?"
        },
        "probe": 1,
        "statuses": {
          "after_error": "IDLE",
          "final": "IDLE"
        }
      },
      "assertions": [
        {
          "expected": "08001",
          "name": "dblink connection SQLSTATE",
          "observed": "08001",
          "passed": true
        },
        {
          "expected": "could not establish connection",
          "name": "dblink connection diagnostic",
          "observed": "could not establish connection",
          "passed": true
        },
        {
          "expected": "IDLE",
          "name": "failed connection attempt leaves session usable",
          "observed": "IDLE",
          "passed": true
        },
        {
          "expected": "OK and remote SELECT 1",
          "name": "correct dblink connection can be repaired",
          "observed": {
            "open": "OK",
            "remote": 1
          },
          "passed": true
        },
        {
          "expected": "OK",
          "name": "named dblink handle is explicitly released",
          "observed": "OK",
          "passed": true
        },
        {
          "expected": "SELECT 1 and IDLE",
          "name": "owner session remains usable",
          "observed": {
            "probe": 1,
            "status": "IDLE"
          },
          "passed": true
        }
      ],
      "cleanup": {
        "case": {
          "errors": [],
          "passed": true
        }
      },
      "limits": "Disposable runner-owned target only; this is a bounded mechanism case, not a guarantee for every client or network path.",
      "image": "postgres:10",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Etc/UTC",
          "backend_pid": 78,
          "binary": {},
          "connection_scope": "runner-owned localhost port",
          "current_user": "postgres",
          "docker": {
            "architecture": "arm64",
            "command": "/usr/local/bin/docker",
            "digest": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "id": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "image": "postgres:10",
            "image_created": "2022-06-23T09:11:18.374607054Z",
            "image_ref": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "log_destination": "csvlog",
            "os": "linux",
            "repo_digests": [
              "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc"
            ]
          },
          "lc_messages": "en_US.utf8",
          "libpq_version": "18.6",
          "locale": "en_US.UTF-8",
          "log_destination": "csvlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
          "server_version_num": "100021",
          "target_kind": "pg10",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "08001",
                "name": "dblink connection SQLSTATE",
                "observed": "08001",
                "passed": true
              },
              {
                "expected": "could not establish connection",
                "name": "dblink connection diagnostic",
                "observed": "could not establish connection",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "failed connection attempt leaves session usable",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "OK and remote SELECT 1",
                "name": "correct dblink connection can be repaired",
                "observed": {
                  "open": "OK",
                  "remote": 1
                },
                "passed": true
              },
              {
                "expected": "OK",
                "name": "named dblink handle is explicitly released",
                "observed": "OK",
                "passed": true
              },
              {
                "expected": "SELECT 1 and IDLE",
                "name": "owner session remains usable",
                "observed": {
                  "probe": 1,
                  "status": "IDLE"
                },
                "passed": true
              }
            ],
            "case_id": "dblink_connect_failure",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.017,
            "observed": {
              "connection_autocommit": true,
              "connection_scope": "server-side dblink connection to the same runner-owned target and a refused runner-local port",
              "dblink_repair": {
                "disconnected": "OK",
                "opened": "OK",
                "remote_probe": 1
              },
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "SqlclientUnableToEstablishSqlconnection",
                "internal_position": null,
                "internal_query": null,
                "message_detail": "could not connect to server: Connection refused\n\tIs the server running on host \"127.0.0.1\" and accepting\n\tTCP/IP connections on port 1?",
                "message_hint": null,
                "message_primary": "could not establish connection",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "dblink.c",
                "source_function": "dblink_connect",
                "source_line": "302",
                "sqlstate": "08001",
                "statement_position": null,
                "table_name": null,
                "text": "could not establish connection\nDETAIL:  could not connect to server: Connection refused\n\tIs the server running on host \"127.0.0.1\" and accepting\n\tTCP/IP connections on port 1?"
              },
              "probe": 1,
              "statuses": {
                "after_error": "IDLE",
                "final": "IDLE"
              }
            },
            "schema": "c08001_dblink_connect_failure",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
