技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
glean-local-dev-loop【数据与研究】Configure Glean local development with mock search responses, test datasources, and connector development workflow. Trigger: "glean dev setup", "glean local development", "glean connector development".
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: glean-local-dev-loop description: 'Configure Glean local development with mock search responses, test datasources, and connector development workflow.
Trigger: "glean dev setup", "glean local development", "glean connector development".
' allowed-tools: Read, Write, Edit, Bash(npm:*), Grep version: 1.8.0 license: MIT author: Jeremy Longshore jeremy@intentsolutions.io tags:
Local development workflow for Glean enterprise search API integration. Provides a fast feedback loop with mock search results, connector testing, and document indexing simulation so you can build custom datasource connectors and search UIs without needing a live Glean deployment. Toggle between mock mode for rapid connector iteration and sandbox mode for validating against your Glean instance.
cp .env.example .env
# Set your credentials:
# GLEAN_API_KEY=glean_xxxxxxxxxxxx
# GLEAN_INSTANCE=https://your-company.glean.com
# MOCK_MODE=true
npm install express axios dotenv tsx typescript @types/node
npm install -D vitest supertest @types/express
// src/dev/server.ts
import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";
const app = express();
app.use(express.json());
const MOCK = process.env.MOCK_MODE === "true";
if (!MOCK) {
app.use("/api", createProxyMiddleware({
target: process.env.GLEAN_INSTANCE,
changeOrigin: true,
headers: { Authorization: `Bearer ${process.env.GLEAN_API_KEY}` },
}));
} else {
const { mountMockRoutes } = require("./mocks");
mountMockRoutes(app);
}
app.listen(3003, () => console.log(`Glean dev server on :3003 [mock=${MOCK}]`));
// src/dev/mocks.ts — realistic enterprise search responses
export function mountMockRoutes(app: any) {
app.post("/api/search", (req: any, res: any) => res.json({
results: [
{ title: "Q4 Engineering Roadmap", url: "https://wiki.co/roadmap", score: 0.97, datasource: "confluence",
snippets: [{ snippet: "The <b>roadmap</b> includes migration to..." }] },
{ title: "Onboarding Guide", url: "https://wiki.co/onboard", score: 0.88, datasource: "notion",
snippets: [{ snippet: "New hire <b>onboarding</b> steps..." }] },
],
totalCount: 2,
}));
app.post("/api/index/documents", (req: any, res: any) => res.json({
status: "OK", documentsIndexed: req.body.documents?.length || 0,
}));
app.get("/api/datasources", (_req: any, res: any) => res.json([
{ name: "confluence", displayName: "Confluence", docCount: 1250 },
{ name: "notion", displayName: "Notion", docCount: 430 },
]));
}
npm run dev:mock & # Start mock server in background
npm run test # Unit tests with vitest
npm run test -- --watch # Watch mode for rapid iteration
MOCK_MODE=false npm run test:integration # Integration test against real Glean instance
curl -X POST http://localhost:3003/api/search -d '{"query":"test"}' to verify mock searchid, title, body.textContent, and datasource fields| Issue | Cause | Fix |
|---|---|---|
401 Unauthorized | Invalid API key or expired token | Regenerate at Glean admin console |
403 Forbidden | Key lacks indexing scope | Request Indexing API permissions from admin |
400 Bad Request | Malformed document payload | Validate required fields: id, title, body |
429 Rate Limited | Too many indexing requests | Batch documents (max 100 per request) |
ECONNREFUSED :3003 | Dev server not running | Run npm run dev:mock first |
Return a local-loop receipt with fixture revision, environment, datasource, tests run, allow/deny outcomes, temporary credential reference, and cleanup state. Exclude tokens, real documents, and search text.
fixtures=v7; mode=mock->sandbox; source=dev-synthetic; tests=12/12; allow=pass; deny=pass; cleanup=complete is a safe promotion candidate.
See glean-debug-bundle.