Skip to content

Commit 8347c99

Browse files
committed
Merge branch 'main' into feature/nested-tests
2 parents c6c1d11 + 899c537 commit 8347c99

22 files changed

+745
-149
lines changed

.github/copilot-instructions.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copilot AI Coding Agent Instructions for Foundatio.Parsers
2+
3+
## Key Principles
4+
5+
All contributions must respect existing formatting and conventions specified in the `.editorconfig` file. You are a distinguished engineer and are expected to deliver high-quality code that adheres to the guidelines in the instruction files.
6+
7+
Let's keep pushing for clarity, usability, and excellence—both in code and user experience.
8+
9+
**See also:**
10+
- [General Coding Guidelines](instructions/general.instructions.md)
11+
- [Testing Guidelines](instructions/testing.instructions.md)
12+
13+
## Key Directories & Files
14+
- `src/Foundatio.Parsers/` — Main library code for Parsers integration.
15+
- `tests/Foundatio.Parsers.Tests/` — Unit and integration tests for Parsers features.
16+
- `build/` — Shared build props, strong naming key, and assets.
17+
- `Foundatio.Parsers.slnx` — Solution file for development.
18+
19+
## Developer Workflows
20+
- **Build:** Use the VS Code task `build` or run `dotnet build` at the repo root.
21+
- **Test:** Use the VS Code task `test` or run `dotnet test tests/Foundatio.Parsers.Tests`.
22+
- **Docker Compose:** For integration tests, run `docker compose up`.
23+
24+
## References & Further Reading
25+
- [README.md](../README.md) — Full documentation, usage samples, and links to upstream Foundatio docs.
26+
- [FoundatioFx/Foundatio](https://github.com/FoundatioFx/Foundatio) — Core abstractions and additional implementations.
27+
28+
---
29+
30+
**If you are unsure about a pattern or workflow, check the README or look for similar patterns in the `src/` and `tests/` folders.**
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
description: "General coding guidelines"
3+
applyTo: "**"
4+
---
5+
6+
# General Coding Guidelines
7+
8+
You are a distinguished engineer and are expected to deliver high-quality code that adheres to the guidelines below.
9+
All contributions must respect existing formatting and conventions specified in the `.editorconfig` file and
10+
Microsoft's [coding conventions](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions).
11+
12+
Code can be formatted with `dotnet format` and checked for errors with `dotnet build`.
13+
14+
Use context7 for documentation
15+
16+
## Code Style & Minimal Diffs
17+
18+
- Match the file's existing style; use `.editorconfig` when unsure.
19+
- Preserve extra spaces, comments, and minimize diffs.
20+
- Always ask before creating new files, directories, or changing existing structures.
21+
- Always look at existing usages before refactoring or changing code to prevent new code from breaking existing code.
22+
- Assume any existing uncommitted code is correct and ask before changing it.
23+
- Don't add code comments unless necessary. Code should be self-explanatory.
24+
- Don't use deprecated or insecure libraries, algorithms or features.
25+
26+
## Modern Code Practices
27+
28+
- Write complete, runnable code—no placeholders or TODOs.
29+
- Use modern language features, clear naming conventions, and defensive coding when necessary.
30+
- Follow SOLID, DRY, and clean code principles. Remove unused code.
31+
32+
## Behavior Management
33+
34+
- Flag any user-visible changes for review.
35+
- Deliver exactly what's requested—avoid adding unnecessary features unless explicitly instructed.
36+
37+
## Security Guidelines
38+
39+
- Sanitize all user inputs and rigorously validate data.
40+
- Follow OWASP guidelines and implement a robust Content Security Policy.
41+
- Adopt Shift-Left security practices to identify vulnerabilities early.
42+
43+
## Developer Planning & Reflection
44+
45+
### Pre-Coding Reflection
46+
47+
1. Identify the problem or feature you're solving.
48+
2. Consider three possible approaches.
49+
3. Choose the simplest approach that satisfies all requirements.
50+
4. Clarify:
51+
- Can the solution be modularized into smaller functions?
52+
- Are there unnecessary abstractions?
53+
- Will the implementation be clear to a junior developer?
54+
55+
### Post-Coding Reflection
56+
57+
1. Review for refactor opportunities—can clarity or maintainability be improved?
58+
2. Identify potential edge cases or areas prone to bugs.
59+
3. Verify robust error handling and validation mechanisms.
60+
61+
## Code Reviews
62+
63+
- Ensure adherence to complexity, consistency, and clean code standards.
64+
- Validate robust error handling and defensive coding practices.
65+
- Check for duplication and maintainable solutions.
66+
67+
## Debugging Guidelines
68+
69+
1. **Reproduce** the issue with minimal steps and code.
70+
2. **Understand** the underlying problem thoroughly.
71+
3. **Form Hypotheses** about the cause.
72+
4. **Test & Verify** potential solutions.
73+
5. **Document** fixes and adjustments clearly for future reference.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: "C# testing guidelines"
3+
applyTo: "tests/**/*.cs"
4+
---
5+
6+
# Testing Guidelines (C#)
7+
8+
## Framework & Best Practices
9+
10+
- Follow Microsoft's [unit testing best practices](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-best-practices).
11+
- Use xUnit as the primary testing framework.
12+
13+
## Test Principles
14+
15+
- **Fast & Isolated**: Tests should execute quickly and not depend on external factors or the order of execution.
16+
- **Repeatable & Self-Checking**: Tests must be consistent and validate their own outcomes without manual checks.
17+
- **Timely**: Write tests alongside your code to ensure relevance and improve design.
18+
19+
## Test Structure & Naming
20+
21+
- Write complete, runnable tests—no placeholders or TODOs.
22+
- Use clear, descriptive naming conventions for test methods:
23+
- `MethodName_StateUnderTest_ExpectedBehavior`
24+
- Follow AAA pattern (Arrange, Act, Assert).
25+
26+
## Test Organization
27+
28+
- Use `[Theory]` and `[InlineData]` for parameterized tests.
29+
- Implement proper setup and teardown using constructors and `IDisposable`.
30+
- Tests are organized to mirror the main code structure (e.g., `Storage/` in both `src` and `tests`).
31+
32+
## Integration Testing
33+
34+
- Inject `ITestOutputHelper` into the test class constructor to get access to the test output.
35+
- Isolate dependencies using test containers, in-memory providers, or stubs to ensure reliable test execution.
36+
- Verify data persistence and side effects.

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM mcr.microsoft.com/mssql/server:2022-latest
2+
3+
ARG SSID_PID=Developer
4+
5+
ENV ACCEPT_EULA=Y
6+
ENV SSID_PID=${SSID_PID}
7+
ENV DEBIAN_FRONTEND=noninteractive
8+
ENV DEBCONF_NONINTERACTIVE_SEEN=true
9+
10+
USER root
11+
12+
RUN apt-get update && \
13+
apt-get upgrade -y && \
14+
apt-get install -yq gnupg gnupg2 gnupg1 curl apt-transport-https && \
15+
curl https://packages.microsoft.com/keys/microsoft.asc -o /var/opt/mssql/ms-key.cer && \
16+
gpg --dearmor -o /etc/apt/trusted.gpg.d/microsoft.gpg /var/opt/mssql/ms-key.cer && \
17+
curl https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list -o /etc/apt/sources.list.d/mssql-server-2022.list && \
18+
apt-get update && \
19+
apt-get install -y mssql-server-fts && \
20+
apt-get clean && \
21+
rm -rf /var/lib/apt/lists
22+
23+
ENTRYPOINT [ "/opt/mssql/bin/sqlservr" ]

build/common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
<Product>Foundatio.Parsers</Product>
66
<Description>A lucene style query parser that is extensible and allows additional syntax features.</Description>
77
<PackageProjectUrl>https://github.com/FoundatioFx/Foundatio.Parsers</PackageProjectUrl>

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
elasticsearch:
3-
image: docker.elastic.co/elasticsearch/elasticsearch:8.18.3
3+
image: docker.elastic.co/elasticsearch/elasticsearch:8.19.5
44
environment:
55
discovery.type: single-node
66
xpack.security.enabled: 'false'
@@ -19,7 +19,7 @@ services:
1919
depends_on:
2020
elasticsearch:
2121
condition: service_healthy
22-
image: docker.elastic.co/kibana/kibana:8.18.3
22+
image: docker.elastic.co/kibana/kibana:8.19.5
2323
ports:
2424
- 5601:5601
2525
networks:
@@ -30,7 +30,9 @@ services:
3030
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:5601/api/status
3131

3232
sqlserver:
33-
image: mcr.microsoft.com/mssql/server:2025-latest
33+
build:
34+
context: .
35+
dockerfile: Dockerfile
3436
ports:
3537
- "1433:1433" # login with sa:P@ssword1
3638
environment:

src/Foundatio.Parsers.ElasticQueries/ElasticMappingResolver.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public FieldMapping GetMapping(string field, bool followAlias = false)
5252

5353
if (_mappingCache.TryGetValue(field, out var mapping))
5454
{
55-
5655
if (followAlias && mapping.Found && mapping.Property is IFieldAliasProperty fieldAlias)
5756
{
5857
_logger.LogTrace("Cached alias mapping: {Field}={FieldPath}:{FieldType}", field, mapping.FullPath, mapping.Property?.Type);
@@ -461,7 +460,6 @@ public static ElasticMappingResolver Create<T>(Func<TypeMappingDescriptor<T>, IT
461460

462461
return Create(mappingBuilder, client.Infer, () =>
463462
{
464-
client.Indices.Refresh(Indices.Index<T>());
465463
var response = client.Indices.GetMapping(new GetMappingRequest(Indices.Index<T>()));
466464
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
467465

@@ -477,7 +475,6 @@ public static ElasticMappingResolver Create<T>(Func<TypeMappingDescriptor<T>, IT
477475

478476
return Create(mappingBuilder, client.Infer, () =>
479477
{
480-
client.Indices.Refresh(index);
481478
var response = client.Indices.GetMapping(new GetMappingRequest(index));
482479
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
483480

@@ -500,7 +497,6 @@ public static ElasticMappingResolver Create<T>(IElasticClient client, ILogger lo
500497

501498
return Create(() =>
502499
{
503-
client.Indices.Refresh(Indices.Index<T>());
504500
var response = client.Indices.GetMapping(new GetMappingRequest(Indices.Index<T>()));
505501
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
506502

@@ -516,7 +512,6 @@ public static ElasticMappingResolver Create(IElasticClient client, string index,
516512

517513
return Create(() =>
518514
{
519-
client.Indices.Refresh(index);
520515
var response = client.Indices.GetMapping(new GetMappingRequest(index));
521516
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
522517

0 commit comments

Comments
 (0)