# larkpal-agent 0.1.9 P0/P1/P2 SIT

This SIT verifies the larkpal -> larkpal-agent@0.1.9 -> MCP Server and
AI_knowledge_dev Scenario Provider chain. It keeps the 0.1.8 P0/P1 checks and
adds the P2 scenario/verifier gate checks.

## Scope

- RunContext construction and propagation from `/api/execute`.
- MCP `tools/call` context headers observed at the real MCP Server/API Server
  HTTP ingress.
- Structured failure semantics from a SIT-only `diagnostic.fail` MCP tool.
- Local scenario loader smoke with the 0.1.8-compatible local schema.
- HTTP scenario provider wiring for AI_knowledge_dev `ai-knowledge.scenario/v1`.
- Structured verifier result callback/SSE/audit承接.
- Final `onResult` status when verifier/artifact/gate fails.

Do not add a diagnostic tool under `src/mcp-server`; that server is the Claude
Code stdio MCP server, not the larkpal-agent HTTP MCP ingress.

## Server Prerequisites

Start the SIT larkpal process with:

```bash
LARKPAL_RUNTIME=larkpal-agent
LARKPAL_AGENT_MCP_SERVER_URL=<sit-mcp-server-url>
LARKPAL_AGENT_SCENARIO_DIRS=/data00/home/zhangchaopeng/projects/larkpal/larkpal/sit/scenarios
```

For P2 HTTP provider checks, also set:

```bash
LARKPAL_AGENT_SCENARIO_PROVIDER_TYPE=http
LARKPAL_AGENT_SCENARIO_PROVIDER_BASE_URL=<ai-knowledge-dev-base-url>
```

The base URL may be either the service origin or the manifest API path. These
are equivalent in larkpal:

```bash
LARKPAL_AGENT_SCENARIO_PROVIDER_BASE_URL=http://10.37.123.26:3000
LARKPAL_AGENT_SCENARIO_PROVIDER_BASE_URL=http://10.37.123.26:3000/api/scenario-manifests
```

Confirm the installed adapter baseline:

```bash
pnpm list @vibe-lark/larkpal-agent
```

Expected baseline: `@vibe-lark/larkpal-agent@0.1.9`.

On the MCP Server/API Server ingress, temporarily log only these headers:

```text
x-tenant-key
x-user-id
x-session-id
x-conversation-id
x-trace-id
x-request-id
```

Do not log `authorization`, `cookie`, `token`, `api-key`, `secret`,
`password`, or `credential` fields.

## Runner

Default header probe:

```bash
pnpm sit:larkpal-agent
```

All P0/P1/P2 probes:

```bash
pnpm sit:larkpal-agent -- --all
```

Targeted probes:

```bash
pnpm sit:larkpal-agent -- --headers
pnpm sit:larkpal-agent -- --failure
pnpm sit:larkpal-agent -- --scenario --missing-scenario
pnpm sit:larkpal-agent -- --contracts
```

Common client-side env:

```bash
LARKPAL_SIT_BASE_URL=http://127.0.0.1:3000
LARKPAL_SIT_TIMEOUT_MS=180000
LARKPAL_SIT_SCENARIO_PROVIDER_BASE_URL=<ai-knowledge-dev-base-url>
```

`LARKPAL_SIT_SCENARIO_PROVIDER_BASE_URL` accepts the same two forms as
`LARKPAL_AGENT_SCENARIO_PROVIDER_BASE_URL`.

## Acceptance

### RunContext / MCP Headers

The runner sends two concurrent `/api/execute` requests with different
`tenantKey`, `userId`, `sessionId`, `conversationId`, `traceId`, and
`requestId`.

Acceptance is manual at the MCP Server/API Server logs: each `tools/call`
must receive headers exactly matching the runner's `expectedMcpHeaders`, with
no tenant/user/session/trace mixing.

### Tool Failure Semantics

The `--failure` probe requires a SIT MCP tool named `diagnostic.fail`.

Expected final result for `ok:false`, `exitCode:2`, and `isError:true` cases:

```json
{
  "subtype": "error_during_execution",
  "isError": true
}
```

The larkpal audit log should also preserve the structured `tool-result`
summary instead of reducing it to natural language.

If `diagnostic.fail` is unavailable, this probe is blocked and should not be
replaced by a natural accidental failure.

### Scenario Loader Smoke

The local fixture is:

```text
sit/scenarios/sit-smoke.scenario.yaml
sit/scenarios/sit-smoke.reference.md
```

The manifest uses the larkpal-agent 0.1.8 local schema and `skills: []`, so it
does not depend on the built-in `convert-to-doc` sample or any registered
skill.

Expected:

- `scenarioId: "sit-smoke"` does not return `SCENARIO_NOT_FOUND` or
  `SCENARIO_SKILL_NOT_FOUND`.
- The final response contains `SIT_SCENARIO_SENTINEL_0_1_8`.
- A deliberately missing scenarioId fails closed and does not complete as
  ordinary chat.

### P2 HTTP Provider And Contract Examples

The `--contracts` probe reads examples from AI_knowledge_dev:

```text
GET /api/scenario-manifests/convert-to-doc/examples/{exampleId}
```

It then sends `/api/execute` requests with `scenarioId: "convert-to-doc"`.
larkpal does not read or interpret the manifest. It only provides run context
and records the runtime's structured events/final status.

Default example ids:

- success
- missing-artifact
- tool-failure
- quality-gate-failure
- forbidden-output

Acceptance:

- `success` may complete as success.
- `missing-artifact`, `tool-failure`, `quality-gate-failure`, and
  `forbidden-output` must not complete as success.
- Chat SSE emits `verifier-result` when the runtime calls
  `onVerifierResult`.
- audit/history/logs preserve structured verifier/tool/final status facts.

If `@vibe-lark/larkpal-agent@0.1.9` is not installed in the running larkpal
process, P2 provider/verifier checks are not valid.
