Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"permissions": {
"allow": [
"Bash(npm:*)",
"Bash(yarn:*)",
"Bash(npx:*)",
"Bash(node:*)",
"Bash(curl:*)",
"Bash(gh:*)",
"Bash(jq:*)",
"Bash(mkdir:*)",
"Bash(docker:*)",
"Bash(docker compose:*)",
"Edit",
"Read",
"Write",
"Grep",
"Glob",
"LS"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
],
"ask": [
"Bash(git push:*)"
]
}
}
195 changes: 195 additions & 0 deletions .claude/skills/run-tests/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
---
name: run-tests
description: Run API tests against InfluxDB 3 Core. Handles service initialization, database setup, and test execution.
author: InfluxData
version: "1.0"
---

# Run Tests Skill

## Purpose

This skill guides running the IoT API test suite against a local InfluxDB 3 Core instance. It covers service setup, database creation, and test execution.
Comment on lines +3 to +12
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The skill description and purpose incorrectly state that tests run "against InfluxDB 3 Core" and require a database instance, which contradicts issue #33 that this PR claims to resolve.

The test suite uses mocks (see tests/api.test.js lines 13-30) and runs without any database connection. According to the design document, the skill should be updated to describe the mocked/unit test workflow, with database setup moved to an optional section for manual testing.

Copilot uses AI. Check for mistakes.

## Quick Reference

| Task | Command |
|------|---------|
| Start InfluxDB 3 | `docker compose up -d influxdb3-core` |
| Check status | `curl -i http://localhost:8181/health` |
| Run tests | `yarn test` |
| View logs | `docker logs influxdb3-core` |

## Complete Setup Workflow

### 1. Initialize InfluxDB 3 Core

```bash
# Create required directories
mkdir -p test/.influxdb3/core/data test/.influxdb3/core/plugins

# Generate admin token (first time only)
openssl rand -hex 32 > test/.influxdb3/core/.token
chmod 600 test/.influxdb3/core/.token

# Start the container
docker compose up -d influxdb3-core

# Wait for healthy status
docker compose ps
```

### 2. Create Databases

```bash
# Get the token
TOKEN=$(cat test/.influxdb3/core/.token)

# Create main database
curl -X POST "http://localhost:8181/api/v3/configure/database" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"db": "iot_center"}'

# Create auth database
curl -X POST "http://localhost:8181/api/v3/configure/database" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"db": "iot_center_auth"}'

# Verify databases exist
curl "http://localhost:8181/api/v3/configure/database?format=json" \
-H "Authorization: Bearer $TOKEN"
```

### 3. Configure Environment

Create `.env.local` if it doesn't exist:

```bash
cat > .env.local << EOF
INFLUX_HOST=http://localhost:8181
INFLUX_TOKEN=$(cat test/.influxdb3/core/.token)
INFLUX_DATABASE=iot_center
INFLUX_DATABASE_AUTH=iot_center_auth
EOF
```

### 4. Run Tests

```bash
# Install dependencies (if needed)
yarn

# Run the test suite
yarn test

# Run with verbose output
yarn test --verbose

# Run specific test file
yarn test __tests__/api.test.js
```

## Troubleshooting

### Container Won't Start

**Symptom:** Container exits immediately

**Check:**
```bash
# View logs
docker logs influxdb3-core

# Verify directories exist
ls -la test/.influxdb3/core/

# Verify token file exists
cat test/.influxdb3/core/.token
```

**Common fixes:**
- Create missing directories: `mkdir -p test/.influxdb3/core/data test/.influxdb3/core/plugins`
- Generate token: `openssl rand -hex 32 > test/.influxdb3/core/.token`

### 401 Unauthorized

**Symptom:** API calls return 401

**Check:**
```bash
# Verify token matches
echo "Token in file: $(cat test/.influxdb3/core/.token)"
echo "Token in .env.local: $(grep INFLUX_TOKEN .env.local)"

# Test with token directly
curl -i http://localhost:8181/api/v3/configure/database \
-H "Authorization: Bearer $(cat test/.influxdb3/core/.token)"
Comment on lines +122 to +128
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The troubleshooting commands use cat test/.influxdb3/core/.token and grep INFLUX_TOKEN .env.local, which violate the Read(./.env.*) deny rule in .claude/settings.json. This is issue #32 and #37 that should be resolved by this PR.

According to the design document, these commands should be replaced with environment variable checks like echo "INFLUX_TOKEN: ${INFLUX_TOKEN:-'(not set)'}" or similar approaches that don't require reading .env files directly.

Suggested change
# Verify token matches
echo "Token in file: $(cat test/.influxdb3/core/.token)"
echo "Token in .env.local: $(grep INFLUX_TOKEN .env.local)"
# Test with token directly
curl -i http://localhost:8181/api/v3/configure/database \
-H "Authorization: Bearer $(cat test/.influxdb3/core/.token)"
# Verify INFLUX_TOKEN environment variable is set
echo "INFLUX_TOKEN: ${INFLUX_TOKEN:-'(not set)'}"
# Test with token directly from environment
curl -i http://localhost:8181/api/v3/configure/database \
-H "Authorization: Bearer ${INFLUX_TOKEN:?INFLUX_TOKEN is not set}"

Copilot uses AI. Check for mistakes.
```

### Database Not Found

**Symptom:** Tests fail with "database not found"

**Fix:** Create the required databases:
```bash
TOKEN=$(cat test/.influxdb3/core/.token)
curl -X POST "http://localhost:8181/api/v3/configure/database" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"db": "iot_center"}'
curl -X POST "http://localhost:8181/api/v3/configure/database" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"db": "iot_center_auth"}'
```

### Port Already in Use

**Symptom:** "port is already allocated"

**Fix:**
```bash
# Find what's using the port
lsof -i :8181

# Stop existing container
docker compose down
```

## Clean Slate

To start fresh:

```bash
# Stop and remove containers
docker compose down

# Remove data (WARNING: deletes all data)
rm -rf test/.influxdb3/core/data/*

# Regenerate token
openssl rand -hex 32 > test/.influxdb3/core/.token

# Start fresh
docker compose up -d influxdb3-core
```

## Test Configuration

The test suite uses these environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `INFLUX_HOST` | `http://localhost:8181` | InfluxDB 3 API URL |
| `INFLUX_TOKEN` | (from `.env.local`) | Admin token |
| `INFLUX_DATABASE` | `iot_center` | Main data database |
| `INFLUX_DATABASE_AUTH` | `iot_center_auth` | Device auth database |
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The database name iot_center_auth is used throughout this file (lines 58, 74, 145, 188), but this is incorrect per issue #34. The project's default in .env.development and throughout the codebase is iot_center_devices for the auth database (INFLUX_DATABASE_AUTH).

According to the design document, all references to iot_center_auth should be changed to iot_center_devices to match the project defaults and prevent "database not found" errors.

Suggested change
| `INFLUX_DATABASE_AUTH` | `iot_center_auth` | Device auth database |
| `INFLUX_DATABASE_AUTH` | `iot_center_devices` | Device auth database |

Copilot uses AI. Check for mistakes.

## Related Files

- **Docker Compose**: `compose.yaml`
- **Test suite**: `__tests__/api.test.js`
- **Environment defaults**: `.env.development`
- **Local overrides**: `.env.local` (gitignored)
13 changes: 10 additions & 3 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Development environment non-secret defaults
# InfluxDB 3 Core configuration

INFLUX_URL=http://localhost:8086
INFLUX_BUCKET=iot_center
INFLUX_BUCKET_AUTH=iot_center_devices
# InfluxDB 3 server URL (default port is 8181)
INFLUX_HOST=http://localhost:8181

# Database names (equivalent to v2 buckets)
INFLUX_DATABASE=iot_center
INFLUX_DATABASE_AUTH=iot_center_devices

# Token should be set in .env.local (not committed to git)
# INFLUX_TOKEN=your_admin_token_here
52 changes: 52 additions & 0 deletions .github/INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# AI Instructions Navigation Guide

This repository has multiple instruction files for different AI tools and use cases.

## Quick Navigation

| If you are... | Use this file | Purpose |
|---------------|---------------|---------|
| **GitHub Copilot** | [../AGENTS.md](../AGENTS.md) | Development patterns, code examples |
| **Claude, ChatGPT, Gemini** | [../AGENTS.md](../AGENTS.md) | Comprehensive development guide |
| **Claude with MCP** | [../CLAUDE.md](../CLAUDE.md) | Quick reference with skill pointers |

## File Organization

```
iot-api-js/
├── .claude/
│ ├── settings.json # Claude permissions
│ └── skills/
│ └── run-tests/SKILL.md # Test execution workflow
├── .github/
│ └── INSTRUCTIONS.md # THIS FILE - Navigation guide
├── AGENTS.md # Comprehensive AI assistant guide
├── CLAUDE.md # Claude with MCP quick reference
└── README.md # User-facing documentation
```

## What's in Each File

**[../CLAUDE.md](../CLAUDE.md)** - Quick reference for Claude:
- Project overview
- Quick commands
- Structure summary
- Links to skills

**[../AGENTS.md](../AGENTS.md)** - Comprehensive guide:
- Architecture diagram
- Development workflow
- Code patterns and examples
- Common tasks
- Style guidelines

**[../README.md](../README.md)** - User documentation:
- Setup instructions
- API usage
- Troubleshooting

## Getting Started

1. **New to the repository?** Start with [../README.md](../README.md)
2. **Using AI assistants?** Read [../AGENTS.md](../AGENTS.md)
3. **Using Claude with MCP?** Check [../CLAUDE.md](../CLAUDE.md) and [../.claude/](../.claude/)
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ yarn-error.log*
.env.development.local
.env.test.local
.env.production.local

# InfluxDB 3 local data
test/.influxdb3/
Loading
Loading