|
| 1 | +--- |
| 2 | +title: Testing utilities |
| 3 | +pcx_content_type: concept |
| 4 | +sidebar: |
| 5 | + order: 12 |
| 6 | +--- |
| 7 | + |
| 8 | +import { TypeScriptExample } from "~/components"; |
| 9 | + |
| 10 | +The Agents SDK provides utilities for testing and validating your Agent implementations. |
| 11 | + |
| 12 | +## Test documentation sync |
| 13 | + |
| 14 | +The `testDocsSync()` function helps validate the automated documentation synchronization workflow between the agents repository and cloudflare-docs. |
| 15 | + |
| 16 | +### Signature |
| 17 | + |
| 18 | +```typescript |
| 19 | +function testDocsSync(options?: TestDocsSyncOptions): TestDocsSyncResult; |
| 20 | +``` |
| 21 | + |
| 22 | +### Parameters |
| 23 | + |
| 24 | +- `options` (optional): Configuration options for the test |
| 25 | + - `message` (string, optional): Custom message to include in the test result |
| 26 | + - `includeTimestamp` (boolean, optional): Whether to include a timestamp in the result |
| 27 | + |
| 28 | +### Returns |
| 29 | + |
| 30 | +- `TestDocsSyncResult`: Object containing test results |
| 31 | + - `success` (boolean): Whether the test succeeded |
| 32 | + - `message` (string): Description of the test result |
| 33 | + - `timestamp` (number, optional): Unix timestamp when the test was run (if `includeTimestamp` was true) |
| 34 | + |
| 35 | +### Example |
| 36 | + |
| 37 | +<TypeScriptExample> |
| 38 | + |
| 39 | +```ts |
| 40 | +import { testDocsSync } from "@cloudflare/agents"; |
| 41 | + |
| 42 | +// Basic usage |
| 43 | +const result = testDocsSync(); |
| 44 | +console.log(result.message); |
| 45 | +// Output: "Docs sync test successful: Default test" |
| 46 | + |
| 47 | +// With custom options |
| 48 | +const customResult = testDocsSync({ |
| 49 | + message: "Testing PR #123", |
| 50 | + includeTimestamp: true |
| 51 | +}); |
| 52 | +console.log(customResult.message); |
| 53 | +// Output: "Docs sync test successful: Testing PR #123" |
| 54 | +console.log(customResult.timestamp); |
| 55 | +// Output: 1731974400000 |
| 56 | +``` |
| 57 | + |
| 58 | +</TypeScriptExample> |
| 59 | + |
| 60 | +## Validate documentation sync bot |
| 61 | + |
| 62 | +The `validateDocsSyncBot()` function validates that the documentation sync bot is configured and working correctly. This is useful in CI/CD pipelines to verify that documentation changes are properly synchronized. |
| 63 | + |
| 64 | +### Signature |
| 65 | + |
| 66 | +```typescript |
| 67 | +function validateDocsSyncBot(): boolean; |
| 68 | +``` |
| 69 | + |
| 70 | +### Returns |
| 71 | + |
| 72 | +- `boolean`: `true` if the bot validation passes, `false` otherwise |
| 73 | + |
| 74 | +### Example |
| 75 | + |
| 76 | +<TypeScriptExample> |
| 77 | + |
| 78 | +```ts |
| 79 | +import { validateDocsSyncBot } from "@cloudflare/agents"; |
| 80 | + |
| 81 | +if (validateDocsSyncBot()) { |
| 82 | + console.log("Documentation sync bot is working correctly"); |
| 83 | +} else { |
| 84 | + console.log("Documentation sync bot validation failed"); |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +</TypeScriptExample> |
| 89 | + |
| 90 | +## CI/CD integration |
| 91 | + |
| 92 | +You can use these utilities in your CI/CD pipeline to verify documentation sync: |
| 93 | + |
| 94 | +<TypeScriptExample> |
| 95 | + |
| 96 | +```ts |
| 97 | +import { testDocsSync, validateDocsSyncBot } from "@cloudflare/agents"; |
| 98 | + |
| 99 | +// Validate bot configuration |
| 100 | +if (!validateDocsSyncBot()) { |
| 101 | + throw new Error("Docs sync bot is not configured correctly"); |
| 102 | +} |
| 103 | + |
| 104 | +// Run test |
| 105 | +const result = testDocsSync({ |
| 106 | + message: `PR #${process.env.PR_NUMBER}`, |
| 107 | + includeTimestamp: true |
| 108 | +}); |
| 109 | + |
| 110 | +console.log(`Test completed at ${new Date(result.timestamp)}`); |
| 111 | +``` |
| 112 | + |
| 113 | +</TypeScriptExample> |
0 commit comments