Interview Handbook by Sayed Elmahdy English

المحور 31 · الـ AI

إزاي توجّه الـ AI وتراجع وراه

Spec-driven development، ومراجعة الـ plan، و checklist لمراجعة كود الـ AI، وأخطاؤه المشهورة في .NET.

15 سؤالJunior · 2Mid · 9Senior · 410 اختيارات

المفاهيم

هنفهم إيه؟ هنستخدم مساعد لتسريع شغل مع بقاء مراجعة السلوك والمسؤولية عند المهندس. هنحوّل طلبًا صغيرًا لمواصفة، نزوّد المساعد بسياق مفيد، ثم نتحقق من الخطة والكود والـ data behavior.

قبل ما تبدأ: يفيدك معرفة أساسيات C# و وasync وكتابة tests. الـ prompt هو التعليمات والمدخلات المرسلة للموديل؛ الـ context هو الكود والقيود والمعلومات المتاحة له؛ وdiff هو التغيير المقترح على الملفات. مش محتاج خبرة في تدريب النماذج، لكن لازم تقدر تشرح الكود الذي تقبله.

المصطلحات اللي تحتها خط منقّط تقدر تضغط عليها لمعرفة معناها، وترجع تكمل من نفس مكانك.

#ليه الأساسيات لسه مهمة؟Why fundamentals still matter

يقدر يكتب endpoint بسرعة، لكنه ممكن ينسى ملكية الـ order أو يعمل خصم مرتين وقت retry. المطلوب من المهندس مش سرعة الكتابة بس: لازم يفهم الـ والـ async والـ database والـ security علشان يراجع السلوك اللي مش ظاهر في happy path.

اعتبر AI مساعد بيقترح تنفيذ. إنت مسؤول عن الرسم، واختبار التحميل، والتسليم؛ شكل الكود المرتب مش شهادة صحة.

اطلب تفسير القرارات، وبعدها تحقّق بنفسك من المصدر والـ الناتج والـ tests. لو مش قادر تشرح مسار الفشل أو إزاي الداتا بتتغير، صغّر المهمة قبل ما تعمل merge. وماتحوّلش كل تعديل صغير لدورة تخطيط طويلة؛ حجم العملية يتناسب مع الخطر.

#Spec-driven development من الطلب للاختبارSpec-driven development from intent to evidence

مثال خطوة بخطوة
  1. بدل طلب «اعمل endpoint للطلبات»، حدد المدخلات ومن المسموح له استخدامها والنتيجة المتوقعة وحالات الفشل. مثل مستخدم يرى طلباته فقط، مع ترتيب ثابت وصفحات محدودة.
  2. قبل التنفيذ اطلب خطة تربط كل شرط بمكان تنفيذه وكيف ستتحقق منه. لو الخطة لا تذكر ملكية الطلب أو حدود الصفحة، النقص ظاهر قبل ما يزيد حجم التغيير.
  3. بعد التنفيذ قارن السلوك بالشروط واختبر حالات الرفض. كود يقبل البناء لا يثبت إن صلاحياته أو قواعد العمل فيه صحيحة.

«اعمل إلغاء order» مش مواصفة كفاية: إمتى الإلغاء مسموح؟ مين المستخدم؟ ولو الدفع حصل؟ امشِ spec → plan → tasks → implement → review. الـ spec بيعرّف سلوك قابل للاختبار؛ الـ plan بيختار التنفيذ؛ والمهام بتقسمه لتغييرات صغيرة قابلة للمراجعة.

Feature: cancel an unpaid order
Actor: authenticated customer who owns the order
POST /orders/{id}/cancel
Pending -> Cancelled; repeat cancellation returns the same successful outcome.
Paid or Shipped -> 409; unknown or another customer's order -> 404.
One transaction changes state, releases reserved stock and writes an outbox event.
Concurrent payment and cancellation cannot both win the state transition.
Non-goals: refunds, shipping cancellation, a new messaging framework.
Acceptance: ownership, repeat calls, concurrent transition and rollback tests.
  1. راجع الـ spec مع صاحب القرار، خصوصًا السباق بين الدفع والإلغاء. لو الدفع وصل متأخر بعد الإلغاء، محتاج مسار reconciliation منفصل.
  2. الـ plan يحدد conditional transition وحدود والـ unique keys.
  3. مهمة أولى بتنفذ شريحة شغالة مع test؛ وبعدها الحالات المنافسة، ثم telemetry. ماتقسّمش لشهور abstractions قبل أول سلوك.
  4. راجع الـ diff مقابل الـ acceptance criteria، وشغّل checks مستقلة عن تفسير الموديل.

الـ spec بيتعدل لو اكتشفت requirement ناقص؛ سجّل التغيير بدل ما تسيبه قرار مخفي في الكود.

#إزاي تراجع الـ plan؟How to review an AI plan

الـ plan المقنع ممكن يسقط requirement مهم. راجعه بسيناريوهات ملموسة قبل ما تقرأ أسماء الـ classes.

اسأل عنالدليل المطلوب
Requirements coverageكل شرط مربوط بخطوة وباختبار
Data modelالمفاتيح، وconstraints، وtenant ownership، وmigration آمنة
إيه atomic؟ وإيه خارج الـ ومحتاج أو reconciliation؟
Securityهوية موثوقة، وresource authorization، وإدارة أسرار
Failure modestimeout وduplicate وpartial failure وconcurrent requests
Testsاختبار يفشل لو العيب الحقيقي رجع، وعلى provider مناسب
Scope creepكل package وabstraction ليهم سبب من الطلب الحالي

اطلب بديل أبسط لو الخطة بتضيف لإجراء محلي أو generic framework لمهمة واحدة. اسأل «إيه اللي هيحصل لو العملية وقفت بعد السطر ده؟» وحدد نقطة التعافي.

#Context يساعد الموديل بدل التخمينContext that reduces guessing

ادّي المساعد الـ spec، والملفات المعنية، ومثال شغال من نفس الـ repo، ونسخ والـ packages، وأوامر التحقق. ملف على طريقة AGENTS.md مفيد للقواعد الثابتة، لكن مش ضمان التزام ولا مكان للأسرار.

# Repository guidance
Target .NET 10; follow the package versions already pinned in this repository.
Read the cancellation spec and the existing order endpoint before editing.
Derive CustomerId from authenticated identity; never trust the request body.
Keep order, reservation and outbox writes in one database transaction.
Change only the order cancellation slice. Explain any new dependency first.
Run the relevant integration tests and report the commands and outcomes.
Do not include customer records, tokens or connection strings in prompts.

Tests عقد للسلوك، مش تفاصيل implementation. خلي في test بيأكد إن عميل تاني مايلغيش الطلب، وtest للتزامن. اطلب diff صغير وتقرير واضح باللي اتنفذ واللي مااتنفذش. شات طويل بمعلومات قديمة ممكن يضر؛ ارجع لمصدر الحقيقة في الملفات.

#Checklist مراجعة كود .NET والـ data mistakesA .NET review checklist and data mistakes

راجع بالترتيب: السلوك والـ edge cases، ثم ownership وsecurity، ثم وconcurrency، ثم async و وlifetime، ثم query shape وperformance، ثم readability والـ tests. الأمثلة الجاية fragments تعليمية؛ db هو scoped ، و ct الطلب، و customerId من هوية متحقق منها.

الخطأالعرضالتحقق
query لكل orderافحص وعدد النداءات
Missing AsNoTrackingtracking غير لازم في قراءة entitiesافحص هل فيه تعديل مقصود
FromSqlRaw interpolationinput بيتحوّل لجزء من SQLparameterization
Missing ownershipأي مستخدم يعرف ID يقرأ orderاختبار مستخدمين مختلفين
❌ N+1 حتى من غير lazy loading
var orders = await db.Orders.ToListAsync(ct);
foreach (var order in orders)
    await db.Entry(order).Collection(o => o.Lines).LoadAsync(ct);
✅ بالمطلوب بس
var summaries = await db.Orders
    .Where(o => o.CustomerId == customerId)
    .Select(o => new { o.Id, LineCount = o.Lines.Count }) // (1)
    .ToListAsync(ct);
❌ Tracking لقراءة entities فقط
var products = await db.Products.ToListAsync(ct);
✅ قراءة entities من غير tracking
var products = await db.Products.AsNoTracking().ToListAsync(ct); // (2)
❌ input جوه SQL syntax
var products = await db.Products
    .FromSqlRaw($"SELECT * FROM Products WHERE Name = '{name}'")
    .ToListAsync(ct);
✅ Interpolated SQL بتعمل parameters
var products = await db.Products
    .FromSql($"SELECT * FROM Products WHERE Name = {name}") // (3)
    .AsNoTracking().ToListAsync(ct);
🧾 شرح الكود
  1. (1) Projection بيخلّي العد يحصل في الـ query بدل تحميل كل الـ lines؛ افحص ترجمة الـ provider.
  2. (2) شيل tracking لما مش هتعدل entities. Projection لقيم scalar بس مش بيتتبع entities أصلًا؛ مش لازم تضيف AsNoTracking لكل query.
  3. (3) FromSql بياخد interpolated string كـ parameters؛ ماتحوّلهاش لـ string مسبقًا. أسماء الجداول والأعمدة محتاجة allowlist، مش value parameters.

توثيق EF SQL

#Async وCancellationToken وDI lifetimeAsync, cancellation and DI lifetimes

الخطأالخطر
.Result و.Waitblocking وthread pool starvation؛ ممكن مع synchronization context
async voidمفيش await أو Task لمراقبة الفشل
Missing CancellationTokenشغل يكمل بعد انتهاء الطلب
Captive dependencysingleton ماسك scoped dependency أطول من عمرها
❌ Blocking
var order = LoadOrderAsync(id, ct).Result;
SaveAsync(ct).Wait();
✅ Await للـ call chain
var order = await LoadOrderAsync(id, ct); // (1)
await SaveAsync(ct);
❌ مفيش Task للمستدعي
public async void SaveOrder() => await db.SaveChangesAsync();
✅ Task وإلغاء
public async Task SaveOrderAsync(CancellationToken ct) // (2)
    => await db.SaveChangesAsync(ct);
❌ الـ بيتوقف هنا
var orders = await db.Orders.ToListAsync();
✅ مرّر الإلغاء
var orders = await db.Orders.ToListAsync(ct); // (3)
❌ Singleton يمسك
services.AddSingleton<OrderReader>();
// OrderReader constructor receives a scoped StoreDbContext.
✅ نفس scope بتاع الطلب
services.AddScoped<OrderReader>(); // (4)
// A singleton worker instead creates a scope per unit of work.
🧾 شرح الكود
  1. (1) await بيسمح بتحرير الـ thread وقت I/O؛ مش محتاج Task.Run علشان تلف query.
  2. (2) المستدعي يقدر يراقب النتيجة والـ exception. async void له مكان في event handlers اللي عقدها void.
  3. (3) الإلغاء تعاوني. بعد side effect حساس استخدم بروتوكول تعافي واضح بدل افتراض إن cancellation عمل rollback.
  4. (4) ده مناسب لخدمة request. worker طويل العمر يستخدم IServiceScopeFactory أو IDbContextFactory، وكل عملية ليها context مستقل.

#Exceptions والوقت وHttpClientExceptions, time and HttpClient

الخطأالمراجعة
Catching Exceptionهل في تعافي حقيقي؟ وهل cancellation بيتعامل صح؟
Swallowed errorsهل الفشل اتقدّم كأنه نجاح؟
DateTime.Nowهل ده instant ولا وقت محلي؟ وهل الاختبار حتمي؟
new HttpClient لكل callهل connection pooling و lifecycle متدارين؟
❌ كل فشل بيتسمّى declined
try { await gateway.ChargeAsync(order, ct); }
catch (Exception) { return PaymentResult.Declined; }
✅ بس الحالة المعروفة
try { await gateway.ChargeAsync(order, ct); }
catch (PaymentDeclinedException) // application-defined exception
{
    return PaymentResult.Declined; // (1)
}
❌ خطأ متبلع ونجاح وهمي
try { await db.SaveChangesAsync(ct); }
catch (Exception) { }
return true;
✅ الفشل يطلع لحد مسؤول
await db.SaveChangesAsync(ct); // (2)
return true;
❌ وقت محلي متغير
order.CreatedAt = DateTime.Now;
✅ TimeProvider متحقن
order.CreatedAt = timeProvider.GetUtcNow(); // (3): DateTimeOffset property
❌ Client جديد لكل طلب
using var client = new HttpClient();
var text = await client.GetStringAsync(url, ct);
✅ Factory بالـ
// At startup:
services.AddHttpClient("payments");
// In a service receiving IHttpClientFactory:
var client = factory.CreateClient("payments"); // (4)
var text = await client.GetStringAsync(url, ct);
🧾 شرح الكود
  1. (1) ده decline معروف فقط؛ timeout ممكن يكون دفع ناجح محتاج reconciliation. catch عام جائز عند global handler أو job boundary لو بيسجّل ويطبق سياسة فشل واضحة.
  2. (2) الفشل بيتنقل للمستدعي؛ لو هتضيف سياق اعمل log مرة عند الحد المناسب، وماترجّعش نجاح.
  3. (3) وقت للاستخدام كـ instant، وTimeProvider للاختبارات. مواعيد الحجز المحلية محتاجة timezone وقواعد مختلفة، مش تحويل أعمى لـ UTC.
  4. (4) الـ factory بيدير handlers. long-lived HttpClient مع PooledConnectionLifetime بديل صحيح؛ المشكلة مش كلمة new لوحدها.

#Hallucinated APIs والـ over-abstractionHallucinated APIs and over-abstraction

الكود المقنع ممكن يستخدم مش موجودة، أو ينزل package اسمها متخيل. راجع الاسم والـ publisher والنسخة من مصدر رسمي قبل restore؛ اسم مألوف مش دليل أمان. الجدول ده بيركّز على علامتين محتاجين توقف.

الخطأالدليلالتصرف
Hallucinated API أو packageمفيش symbol في النسخة المثبتة أو مصدر موثوقتحقق من docs والـ package metadata وابنِ الكود
Over-abstractionطبقات ومفاهيم مالهاش طلب حاليتنفيذ مباشر لحد ما يظهر اختلاف حقيقي
❌ API متخيلة: مش
// Deliberately invalid: do not install a package to make this name work.
var orders = await db.Orders.FetchAllSafelyAsync(ct);
✅ API موجودة ومحددة السلوك
var orders = await db.Orders.AsNoTracking()
    .Where(o => o.CustomerId == customerId).ToListAsync(ct);
❌ Abstraction لمعادلة واحدة
public interface IOrderTotalStrategy
{
    decimal Calculate(decimal subtotal, decimal delivery);
}
// Plus a factory and resolver for a single implementation.
✅ سلوك واضح قابل للاختبار
public static decimal CalculateTotal(decimal subtotal, decimal delivery)
{
    ArgumentOutOfRangeException.ThrowIfNegative(subtotal);
    ArgumentOutOfRangeException.ThrowIfNegative(delivery);
    return subtotal + delivery;
}

ابدأ interface لما فيه حد خارجي أو اختلاف فعلي أو حاجة للاختبار تستحقه. ماتحذفش abstraction موجودة من غير فهم المستهلكين. والـ build ضروري بس مش كفاية: API حقيقية ممكن تتستخدم غلط.

#Security والـ licenses وقياس الجودةSecurity, licenses and measuring quality

قبل إدخال كود أو بيانات في أداة ، راجع سياسة المؤسسة وإعدادات retention والتدريب ومكان معالجة البيانات. استخدم بيانات مصطنعة، وماتبعثش أو connection strings. افحص dependencies والـ lock file والـ licenses للنسخ المختارة، وخلي قرار المتطلبات القانونية عند المختص.

تغيّرت تراخيص MediatR وAutoMapper في 2025، وFluentAssertions v8 بقى له متطلبات تجارية لاستخدامات معينة؛ راجع الترخيص الفعلي وإعفاءاته بدل افتراض إن كل نسخة مجانية أو كل استخدام مدفوع. بدائل assertions تشمل AwesomeAssertions وShouldly. المعلومة دي سبب للمراجعة، مش حكم قانوني.

مقياسطريقة مفيدة
الصحةacceptance pass rate وescaped defects وشدة العيوب
التسليموقت المهمة شامل review وإعادة الشغل
الصيانةحجم الـ diff ووضوح المسؤوليات والقدرة على شرح الكود
التشغيل وquery count وأخطاء production
التكلفةتكلفة الأدوات مع وقت المراجعة لكل تغيير مقبول

عدد السطور والـ prompts مش إنتاجية. قارن مهام متشابهة في الحجم والخطر، وسجّل العوامل اللي بتأثر على المقارنة.

أسئلة الانترفيو

راجع فهمك

ليه الاختيار ده مناسب؟ إمتى ممكن ماينفعش؟ وإيه اللي هيتغير لو الحمل زاد أو ظهر فشل؟

31.1Why do fundamentals matter if AI can write the code?Junior

الـ compiler مايعرفش business intent. لازم تفهم async و وsecurity علشان تكتشف الـ race أو ownership الناقصة. المسؤولية عن الكود بتفضل عند الفريق اللي اعتمده.

الإجابة النموذجية (English)

I still need fundamentals because generated code can compile while violating business rules. A compiler cannot tell whether a customer owns an order, whether two requests can oversell stock, or whether a retry charges twice. I use to accelerate exploration and implementation, then apply my understanding of databases, concurrency and security to review the result. I only accept code I can explain and support. The team remains responsible for what it ships, regardless of who produced the first draft.

31.2What does spec-driven development mean in practice?Mid

مواصفة بسلوك وحالات فشل وnon-goals، بعدها خطة ومهام صغيرة وتنفيذ ومراجعة. الـ acceptance criteria بتربط الكلام بالاختبار، والـ spec يتحدث لو القرار اتغيّر.

الإجابة النموذجية (English)

I start with a spec describing observable behavior, constraints, failure cases and explicit non-goals. I review a plan that maps those requirements to data changes, boundaries and tests, then implement small vertical slices. Review compares the resulting behavior and diff with the spec rather than merely checking whether the code looks sensible. When a requirement changes, I update the spec and tests together. I keep the ceremony proportional to the risk and size of the change.

31.3How would you review an AI-generated implementation plan?Mid

اربط كل requirement بخطوة واختبار. بعدين افحص data model وconstraints و وsecurity والفشل والتزامن. اسأل عن أي dependency أو layer جديدة وهل لها ضرورة حالية.

الإجابة النموذجية (English)

I check that every acceptance criterion has an implementation step and meaningful verification. Then I inspect the data model, constraints, ownership checks, boundaries and external side effects. I walk through duplicate requests, concurrent changes, timeouts and partial failure. I also ask whether each new package and abstraction solves a present requirement. If the plan is much larger than the feature, I request a simpler alternative. A plan is ready when its important assumptions and recovery paths are explicit.

31.4What context should you give an AI coding assistant?Junior

الطلب والـ non-goals، والنسخ، والملفات المعنية، ومثال من المشروع، وأوامر التحقق. ماتحطش أسرار، وماتكتفيش بوصف قديم لما الملفات الحالية متاحة.

الإجابة النموذجية (English)

I provide the current requirement, non-goals, relevant files, repository conventions and the versions already in use. I include a working example from the codebase and the exact checks needed for the change. Stable guidance belongs in a short repository instruction file, while task-specific decisions belong with the spec. I avoid secrets and customer data, and prefer focused context over dumping the whole repository. I also ask the assistant to identify missing information rather than invent or requirements.

31.5Why is a passing build insufficient evidence for AI-written code?Mid

Build يثبت types وsyntax، مش إن الـ صح أو الاستعلام parameterized أو المستخدم صاحب الـ order. محتاج tests وسيناريوهات فشل ومراجعة وصلاحيات.

الإجابة النموذجية (English)

A build checks syntax, references and type rules, but it cannot prove the intended behavior. An endpoint can compile and still leak another customer's data, issue an query pattern or return success after swallowing a failure. I require acceptance tests for the business behavior, integration tests where database semantics matter, and review of security and failure paths. I inspect the actual diff and relevant runtime evidence. A model's claim that everything is correct is not an independent check.

31.6How do you catch N+1 and unnecessary tracking?Mid

راجع loops وlazy loading أو explicit loading، وسجّل عدد commands. استخدم للـ وAsNoTracking لقراءة entities فقط. tracking مطلوب لو هتعدل بالـ context.

الإجابة النموذجية (English)

I inspect loops and access, then verify generated and command counts with representative data. I usually project the response shape in the database rather than loading entire graphs. For read-only entity queries, AsNoTracking avoids unnecessary change tracking. I do not add it mechanically to scalar projections, which do not track entities anyway, or to workflows that intentionally update tracked entities. The important evidence is bounded database work and the correct update behavior, not simply the presence of a particular method call.

31.7What async mistakes do you look for in generated .NET code?Mid

.Result و.Wait وasync void ونسيان await وCancellationToken. كمان fire-and-forget جوه request وqueries متوازية على نفس . مش كل async محتاج Task.Run.

الإجابة النموذجية (English)

I look for .Result and .Wait, async void outside event handlers, missing awaits and cancellation that stop at an intermediate method. I also check for fire-and-forget work using request-scoped services and concurrent operations on one . In , blocking tasks can starve the thread pool even without the classic synchronization-context . I use genuine async throughout the call chain and durable background processing for work that must survive the request or process.

31.8What is a captive dependency?Mid

Dependency قصيرة العمر ممسوكة من service أطول عمرًا؛ المثال singleton يمسك scoped . صحّح lifetime أو اعمل scope لكل unit of work في worker.

الإجابة النموذجية (English)

A captive dependency occurs when a longer-lived service retains a dependency that should have a shorter lifetime. A singleton holding a scoped is a common example: the context can outlive its intended unit of work and be accessed concurrently. I review registrations as well as constructors. A request service can become scoped, while a singleton background worker can create a scope or use a context factory per operation. Making the DbContext singleton does not solve the problem.

31.9How do you review FromSqlRaw for injection risks?Mid

لو string interpolation حصلت قبل FromSqlRaw، القيم بقت syntax. استخدم FromSql بـ interpolated string أو parameters صريحة. identifiers محتاجة allowlist، والـ authorization لسه واجبة.

الإجابة النموذجية (English)

I check whether untrusted values are concatenated or interpolated into a string passed to FromSqlRaw. That makes them part of syntax and creates an injection risk. I use a parameterizing such as FromSql with an interpolated string, or explicit parameters for raw SQL. Dynamic identifiers cannot be parameterized as values, so they need a strict allowlist. Parameterization does not replace authorization: the query still has to restrict results to the authenticated user's permitted data.

31.10When is catching Exception acceptable?Senior

عند global handler أو worker boundary بسياسة فشل واضحة، مش علشان نرجّع نجاح كاذب. فرّق cancellation والحالات المتوقعة، وماتكرر log في كل طبقة.

الإجابة النموذجية (English)

I allow broad exception handling at a responsible boundary, such as an exception handler or a background job runner, when it records failure and applies a clear policy. Inside business logic I prefer specific exceptions only when I can recover or translate a known outcome. I do not turn an unknown payment failure into a decline, because the payment may have succeeded. Cancellation should be handled deliberately, and exceptions should not be swallowed or logged repeatedly at every layer.

31.11How do you make time-dependent generated code testable?Mid

TimeProvider بالـ ، وGetUtcNow للـ instants، واختبارات لحدود انتهاء الصلاحية. الوقت المحلي للحجوزات محتاج timezone، مش DateTime.Now من السيرفر.

الإجابة النموذجية (English)

I inject TimeProvider instead of reading machine time throughout the code. For timestamps representing instants, I normally use GetUtcNow and DateTimeOffset, then control the clock in tests for expiry boundaries and retries. I distinguish that from local civil schedules, such as a booking at nine in a particular time zone, which need zone and daylight-saving rules. Replacing every time value with mechanically can lose business meaning; the representation should match the domain.

31.12How do you handle hallucinated packages and licensing risks?Senior

تحقق من المصدر والاسم والـ publisher والنسخة والـ license قبل restore. Build مش كفاية لو package خبيثة موجودة بنفس الاسم. راجع التحديثات وحدود الاستخدام مع المختص.

الإجابة النموذجية (English)

I verify proposed packages against official documentation, trusted registries and the publisher's repository before adding them. I check the exact version, transitive dependencies, security advisories and license terms rather than assuming a familiar library remains free under every version. An invented package name can become a supply-chain risk if someone publishes it. I keep changes explicit in the dependency diff and escalate unclear licensing requirements to the appropriate reviewer. Successful compilation alone does not establish provenance or acceptable terms.

31.13How do you prevent AI-generated over-engineering?Senior

Non-goals واضحة، واطلب سبب لكل layer أو package. نفّذ شريحة صغيرة واختبر السلوك. ماتضيفش strategy factory لعملية واحدة إلا لو فيه سبب حقيقي.

الإجابة النموذجية (English)

I define non-goals and ask how each new layer, abstraction or dependency supports a current requirement. I prefer a small working slice with observable behavior before generalizing. If there is only one implementation and no meaningful boundary, a direct method may be clearer than a factory and strategy hierarchy. I still preserve existing architectural boundaries where they serve real consumers. The goal is a change that is easy to review and maintain, with complexity justified by evidence rather than hypothetical future flexibility.

31.14What makes a useful test contract for an AI task?Mid

اختبار سلوك واضح يفشل لو regression رجع. في cancellation اختبر ownership وduplicate وconcurrent transition وrollback. ماتختبرش إن method داخلية اتندهت من غير داعي.

الإجابة النموذجية (English)

I write acceptance criteria around observable outcomes and important . For order cancellation, that includes ownership, repeated requests, incompatible states, concurrent payment and rollback of related writes. Tests should fail if those rules break, without mirroring private helper calls or the current class layout. I use the real database provider where or query translation matter. I also review test assertions, because generated tests can pass while checking nothing important or reproducing the same misunderstanding as the implementation.

31.15How would you measure whether AI improves engineering productivity?Senior

قِس وقت التسليم شامل review وإعادة الشغل، وescaped defects، والتكلفة، ومقاييس التشغيل. قارن مهام متشابهة، وماتعتبرش عدد السطور إنتاجية.

الإجابة النموذجية (English)

I measure delivery time including review and rework, alongside acceptance quality, escaped defects and operational outcomes. I include tool spend and maintenance effort rather than counting only the time to generate a draft. Comparisons need similar task size and risk, with enough observations to avoid drawing conclusions from one easy change. I also check whether the team can explain and modify the result. More generated lines or more accepted suggestions can coexist with worse engineering outcomes.

اختبر نفسك

إجابات الاختبار وعلامات إكمال المحاور بتتحفظ على المتصفح ده، ومش بتتنقل لأجهزة تانية.

النتيجة: 0 / 0

Which spec is most useful for an AI implementer?

المواصفة بتحدد السلوك والحدود، مش أسماء classes بس.

What is wrong with FromSqlRaw($"... Name = '{name}'")?

استخدم FromSql مع interpolation أو parameters صريحة.

A singleton worker needs DbContext. What should it do?

الـ context قصير العمر ومش thread-safe.

When is AsNoTracking especially useful?

بيقلل tracking غير المطلوب، مش بيضيف صلاحيات.

Why inject TimeProvider?

تقدر تختبر expiry من غير انتظار حقيقي.

A generated package name looks plausible. Next step?

الاسم المتخيل ممكن يبقى supply-chain risk.

Which result best indicates an AI workflow improvement?

المراجعة وإعادة الشغل جزء من التكلفة.

A payment call times out. What should review reject?

timeout مش دليل إن الدفع ماحصلش.

What is the strongest evidence that an AI change meets the task?

لازم تحقق مستقل مرتبط بالمطلوب.

Which HttpClient lifetime approach is valid?

الاتنين بيسمحوا بإدارة connection reuse و بشكل مقصود.